[英]Save the Image of activity on click of menu item
I have and activity where on click of menu item save I want to save the image of the screen to my device inside aa specific folder. 我有一个活动,单击菜单项后要保存,我想将屏幕图像保存到我的设备中的特定文件夹中。 how can I do it.
我该怎么做。 ?
?
The image which is displayed in the background is a ImageView and the text is textview. 在后台显示的图像是ImageView,文本是textview。 I have to merge them and save them as a single image.
我必须合并它们并将它们保存为单个图像。
Try with below code on menu item click event.... 尝试在菜单项单击事件上使用以下代码。
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();
}
where view v is root layout... 其中视图v是根布局...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.