我有两个按钮和一个mapView。当我按下其中一个按钮时,我想保存MapView的视图。
任何人都知道如何做到这一点?
答案 0 :(得分:3)
你必须为按钮添加一个监听器(你应该知道这是怎么做的)并且在那个监听器中,做类似的事情:
boolean enabled = mMapView.isDrawingCacheEnabled();
mMapView.setDrawingCacheEnabled(true);
Bitmap bm = mMapView.getDrawingCache();
/* now you've got the bitmap - go save it */
File path = Environment.getExternalStorageDirectory();
path = new File(path, "Pictures");
path.mkdirs(); // make sure the Pictures folder exists.
File file = new File(path, "filename.png");
BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(file));
boolean success = bm.compress(CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
mMapView.setDrawingCacheEnabled(enabled); // reset to original value
为了让图像立即显示在图库中,您必须向MediaScanner通知新图像,如下所示:
if (success) {
MediaScannerClientProxy client = new MediaScannerClientProxy(file.getAbsolutePath(), "image/png");
MediaScannerConnection msc = new MediaScannerConnection(this, client);
client.mConnection = msc;
msc.connect();
}
答案 1 :(得分:1)
答案 2 :(得分:0)
Bitmap bitmapMapsattelite ;
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
// Make a snapshot when map's done loading
map.snapshot(new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
bitmapMapsattelite = null;
bitmapMapsattelite = bitmap;
}
});
}
});