如何使用 imageview onclick 保存位图图像

编程入门 行业动态 更新时间:2024-10-10 04:21:36
本文介绍了如何使用 imageview onclick 保存位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发 android 中的图像着色.因此,当我单击另一个图像视图(如保存)时,将颜色应用于我的图像后,我必须将该图像保存到图库.

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.

推荐答案

从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 { bmpress(Bitmap.CompressFormat.PNG, 100, fOut); fOut.flush(); fOut.close(); } catch (Exception e) { }

更多推荐

如何使用 imageview onclick 保存位图图像

本文发布于:2023-11-13 03:13:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   如何使用   图像   onclick   imageview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!