捕獲GoogleMap Android API V2的屏幕截圖使用舊版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();但我得到的截圖沒有任何地圖內容,看起來像這樣: 有沒有人想出如何截取新的谷歌地圖Android API V2的截圖?
添加回答
舉報
0/150
提交
取消