如何保存与ImageView的位图图像的onclick [英] How to save a bitmap image with imageview onclick
本文介绍了如何保存与ImageView的位图图像的onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在开发的图像在android的着色。因此,应用色彩来我的形象,当我点击另一个imageview的像保存后,以后我就保存图像gallery.So可有人告诉我,我该怎么办???达
Am developing a coloring of images in android. So after applying colors to my image when i click another imageview like save, then i have to save that image to gallery.So can someone tell me how can i do tat???
推荐答案
要得到ImageView的位图:
To get bitmap from imageview:
imageview.buildDrawingCache();
Bitmap bm=imageview.getDrawingCache();
要保存在一个文件中:
OutputStream fOut = null;
Uri outputFileUri;
try {
File root = new File(Environment.getExternalStorageDirectory()
+ File.separator + "folder_name" + File.separator);
root.mkdirs();
File sdImageMainDirectory = new File(root, "myPicName.jpg");
outputFileUri = Uri.fromFile(sdImageMainDirectory);
fOut = new FileOutputStream(sdImageMainDirectory);
} catch (Exception e) {
Toast.makeText(this, "Error occured. Please try again later.",
Toast.LENGTH_SHORT).show();
}
try {
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
}
这篇关于如何保存与ImageView的位图图像的onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文