我有一个活动,单击菜单项后会在其中保存,我想将屏幕图像保存到特定文件夹内的设备中。我该怎么做。 ?
在后台显示的图像是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();
}
其中视图v是根布局...