我正在开发一个Android应用程序,它截取包含谷歌地图的片段的截图。当用户点击分享按钮时,它会获取片段视图的屏幕截图,并允许用户通过电子邮件分享。以下是我的片段视图。
以下是我拍摄屏幕截图的代码:
public static File takeScreenShot(View view) {
String path = Environment.getExternalStorageDirectory().toString() + "/" + System.currentTimeMillis()+ ".jpg";
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
OutputStream out = null;
File imageFile = new File(path);
try {
out = new FileOutputStream(imageFile);
// choose JPEG format
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
} catch (FileNotFoundException e) {
// manage exception
} catch (IOException e) {
// manage exception
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception exc) {
}
}
return imageFile;
}
以下是共享地图视图的代码
Intent intentShare = new Intent(Intent.ACTION_SEND);
intentShare.setType("image/*");
intentShare.putExtra(Intent.EXTRA_STREAM, Uri.parse(ScreenShotTaker.takeScreenShot(view).toURI().toString()));
startActivity(intentShare);