问题
I am wondering to know about how to get snapshot from SupportMapFragment. I have no idea. Please help.
Thanks for your advance.
回答1:
You can try to take a screen shot of the fragment View:
View view = findViewById(R.id.fragmentId);
view.setDrawingCacheEnabled(true);
Bitmap bitmap = view.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
I haven't tested it.
回答2:
To get a drawable you can implement this code:
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap snapshot) {
mapSnapshot = snapshot;
}
};
googleMap.snapshot(callback);
Drawable screenshot = new BitmapDrawable(getResources(),mapSnapshot);
If you directly want to save the snapshot on the SD, you can follow this answer: Capture screen shot of GoogleMap Android API V2
回答3:
The latest update of Google Play Services library brings us ability to make snapshots via GoogleMap's snapshot() method.
来源:https://stackoverflow.com/questions/16435842/how-to-get-snapshot-from-google-map-v2