打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android 保存图片到SQLite,读出SQLite中的图片
Android 保存图片到SQLite,读出SQLite中的图片
http://zhangfan822.iteye.com/blog/1883118
1、bitmap保存到SQLite 中 数据格式:
Java代码
db.execSQL("Create table express ( _id INTEGER PRIMARY KEY AUTOINCREMENT,express_no varchar(100),express_name TEXT,express_img BLOB );");
2、bitmap 变为 Blob
Java代码
ContentValues values = new ContentValues();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
values.put("express_img", os.toByteArray());
values.put("express_name","zf");
values.put("express_no","zf");
getContentResolver().insert("express", values);
3、从SQLite中读取Bitmap
Java代码
byte[] in=cur.getBlob(cur.getColumnIndex("express_img"));
bmpout=BitmapFactory.decodeByteArray(in,0,in.length);
显示在ImageView上
Java代码
ImageView imageView = (ImageView) view.findViewById(R.id.img);
ByteArrayInputStream stream = new ByteArrayInputStream(cur.getBlob(cur.getColumnIndex("express_img")));
imageView.setImageDrawable(Drawable.createFromStream(stream, "img"));
总结:
inputStream:  作为数据缓存,数据写如何供别的对象读取,其方法为read();
outputStream:作为数据缓存,将来向别的对象写内容!其方法write();
Java代码
byte[] in=cur.getBlob(cur.getColumnIndex(MyUser.User.BITMAP_VALUES));
//这样也可以对数据进行初始化,byte是基本类型,不需要之前进行长度定义。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
android matrix - qianda115的日志 - 网易博客
8.1.2 Android中的13种Drawable小结 Part 2
android imageView释放内存
一个千万量级的APP使用的一些第三方库
android 图片处理(截取,缩放)
Android控件Gallery3D效果
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服