我有一个 Activity ,在单击菜单项“保存”时,我想将屏幕图像保存到我的设备的特定文件夹内。我该怎么做。 ?
背景显示的图像是ImageView,文本是textview。我必须合并它们并将它们保存为单个图像。
最佳答案
尝试在菜单项点击事件上使用以下代码......
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
// give path of external directory to save image
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "test.jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
其中 View v 是根布局...
关于java - 单击菜单项保存 Activity 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23653482/