sqlite 存储图片

sqlite 存储图片,第1张

概述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   

1、bitmap保存到sqlite 中 数据格式:

Java代码 db.execsql("Createtableexpress(_IDINTEGERPRIMARYKEYautoINCREMENT,express_novarchar(100),express_nameTEXT,express_imgBLOB);");

2、bitmap 变为 Blob

ContentValuesvalues=newContentValues(); Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.erweima); finalByteArrayOutputStreamos=newByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG,100,os); values.put("express_img",os.toByteArray()); values.put("express_name","zf"); values.put("express_no",250); line-height:18px"> getContentResolver().insert("express",values);

3、从sqlite中读取Bitmap

byte
[]in=cur.getBlob(cur.getColumnIndex("express_img")); bmpout=BitmapFactory.decodeByteArray(in,0)">0,in.length);

显示在ImageVIEw上

ImageVIEwimageVIEw=(ImageVIEw)vIEw.findVIEwByID(R.ID.img); ByteArrayinputStreamstream=newByteArrayinputStream(cur.getBlob(cur.getColumnIndex("express_img"))); imageVIEw.setimageDrawable(Drawable.createFromStream(stream,"img"));

总结:

inputStream: 作为数据缓存,数据写如何供别的对象读取,其方法为read();

outputStream:作为数据缓存,将来向别的对象写内容!其方法write();

byte[]in=cur.getBlob(cur.getColumnIndex(MyUser.User.BITMAP_VALUES));

//这样也可以对数据进行初始化,byte是基本类型,不需要之前进行长度定义。

总结

以上是内存溢出为你收集整理的sqlite 存储图片全部内容,希望文章能够帮你解决sqlite 存储图片所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1180255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存