how to take snapshot of google map?
I need to take snapshot of google map and save in local database. Please help me to tak开发者_开发知识库e the snapshot of google map.
Thanks, Monali
You can't make a print screen from inside your app unless the phone is rooted (don't have the code for that).
You can however make a print screen thru the emulator but that not the question here.
For the sake of completeness:
Emulator printscreen
You have to connect your phone via USB, go to Debug perspective in Eclipse, select the "Devices" tab, select your device in the list and click the "Screen Capture" icon.
You can see this library http://code.google.com/p/android-screenshot-library/ . It runs in background and can allow you to make screenshots without root.
Define function in button click event;
Button btnCap = (Button) findViewById(R.id.btnTakeScreenshot);
btnCap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
CaptureMapScreen();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
Here is a function CaptureMapScreen()
public void CaptureMapScreen()
{
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
Bitmap bitmap;
@Override
public void onSnapshotReady(Bitmap snapshot) {
// TODO Auto-generated method stub
bitmap = snapshot;
try {
FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
+ "MyMapScreen" + System.currentTimeMillis()
+ ".png");
// above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
};
myMap.snapshot(callback);
// myMap is object of GoogleMap +> GoogleMap myMap;
// which is initialized in onCreate() =>
// myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
}
public void getSnapShot(){
GoogleMap.SnapshotReadyCallback callback=new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
}
};
google_Map.snapshot(callback);
}
精彩评论