Android将图片转为字节流存储在SharedPreferences
2017-01-22 11:09
351 查看
public static void putImageToShare(Context mContext, ImageView imageView) { BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); Bitmap bitmap = drawable.getBitmap(); ByteArrayOutputStream byStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 80, byStream); byte[] byteArray = byStream.toByteArray(); String imgString = new String(Base64.encodeToString(byteArray, Base64.DEFAULT)); ShareUtils.putString(mContext, "image_title", imgString); L.e(imgString); } public static void getImageToShare(Context mContext, ImageView imageView) { String imgString = ShareUtils.getString(mContext, "image_title", ""); if (!imgString.equals("")) { byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT); ByteArrayInputStream byStream = new ByteArrayInputStream(byteArray); Bitmap bitmap = BitmapFactory.decodeStream(byStream); imageView.setImageBitmap(bitmap); } }
相关文章推荐
- Android中图片URI如何转换成对应的存储路径
- 【转】android:网络图片转为bitmap 保存至SD卡中
- Android应用开发之图片(Bitmap)压缩(一)---------Bitmap与BitmapFactory的认识及图片的存储形式大小的实验
- android圆形头像的选择和剪切并存储出圆形图片
- Android中图片URI如何转换成对应的存储路径
- android 网络获取图片并存储
- 用sqlite存储Android手机图片,再从数据库读出图片显示。
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- Android开发之异步任务加载网络图片并存储在sdcard中(源代码分享)
- android创建数据库(SQLite)保存图片示例ZZ 分类: Android数据存储 2015-03-22 09:58 41人阅读 评论(0) 收藏
- Android图片转为16进制
- android开发-通过HttpURLConnection获取网络内容,Bitmap把二进制格式的图片转为位图
- android异步获取图片并且本地存储的后续问题
- 【Android Developers Training】 59. 管理图片存储
- android 将文字转为为图片
- 生成黑白画笔,android使用系统浏览器打开网页,将Bitmap图片存储在本地JPG文件的方法
- android 图片存储到sqlite
- 图片以BLOB存储在后台数据库中,Android客户端要进行读取显示
- Android 保存图片到SQLite,读出SQLite中的图片 分类: Android数据存储 2015-03-22 09:59 39人阅读 评论(0) 收藏