【发布时间】:2012-11-26 06:07:44
【问题描述】:
最终更新
Google 已满足功能请求。请看this answer below.
原始问题
使用旧版本的 Google Maps Android API,我能够截取谷歌地图的屏幕截图以通过社交媒体分享。我使用以下代码捕获屏幕截图并将图像保存到文件中,效果很好:
public String captureScreen()
{
String storageState = Environment.getExternalStorageState();
Log.d("StorageState", "Storage state is: " + storageState);
// image naming and path to include sd card appending name you choose for file
String mPath = this.getFilesDir().getAbsolutePath();
// create bitmap screen capture
Bitmap bitmap;
View v1 = this.mapView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
String filePath = System.currentTimeMillis() + ".jpeg";
try
{
fout = openFileOutput(filePath,
MODE_WORLD_READABLE);
// Write the string to the file
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
Log.d("ImageCapture", "FileNotFoundException");
Log.d("ImageCapture", e.getMessage());
filePath = "";
}
catch (IOException e)
{
// TODO Auto-generated catch block
Log.d("ImageCapture", "IOException");
Log.d("ImageCapture", e.getMessage());
filePath = "";
}
return filePath;
}
但是,API V2 使用的新 GoogleMap 对象没有 MapView 那样的“getRootView()”方法。
我尝试过这样做:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.basicMap);
View v1 = mapFragment.getView();
但我得到的截图没有任何地图内容,看起来像这样:
有人知道如何截取新的 Google Maps Android API V2 的屏幕截图吗?
更新
我也试过这样获取rootView:
View v1 = getWindow().getDecorView().getRootView();
这会生成一个屏幕截图,其中包含屏幕顶部的操作栏,但地图仍然是空白的,就像我附上的屏幕截图一样。
更新
功能请求已提交给 Google。如果您希望 Google 将来添加此功能请求,请为功能请求添加星标:Add screenshot ability to Google Maps API V2
【问题讨论】:
-
现在他们使用向量是我在某些地方读到的。不知道该怎么做
标签: android android-mapview google-maps-android-api-2