捕获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的截图?
繁华开满天机
相关分类