mon*_*rcg 4 android android-mapview
我有两个按钮和一个 mapView。当我按下其中一个按钮时,我想保存 MapView 的视图。
任何人都知道我该如何做到这一点?
您必须向按钮添加一个侦听器(您应该知道这是如何完成的)并在该侦听器中执行以下操作:
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
Run Code Online (Sandbox Code Playgroud)
为了让图像立即显示在图库中,您必须像这样通知 MediaScanner 新图像:
if (success) {
MediaScannerClientProxy client = new MediaScannerClientProxy(file.getAbsolutePath(), "image/png");
MediaScannerConnection msc = new MediaScannerConnection(this, client);
client.mConnection = msc;
msc.connect();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2157 次 |
| 最近记录: |