[英]how can I store image and retrieve the same in sqlite-android
I am developing an application that stores some static images in sqlite and I want to retrieve the same in a imageview. 我正在开发一个在sqlite中存储一些静态图像的应用程序,我想在imageview中检索相同的图像。 how do I do this thanks. 我该怎么做谢谢。
sqlite3 supports the blob
type, you can save the bitmap content using the blob
type. sqlite3支持blob
类型,您可以使用blob
类型保存位图内容。
However, the blob
type has a size limit, and to save to a blob type is difficult. 但是, blob
类型具有大小限制,并且难以保存为斑点类型。
So, I suggest to save the bitmap local or on the sdcard, and save the path in the database. 因此,我建议将位图保存在本地或sdcard上,并将路径保存在数据库中。
added : 添加 :
table define a column with name 'image' using blob
type 表使用blob
类型定义名称为“ image”的列
Bitmap map = ...;
ByteArrayOutputStream bufferStream = new ByteArrayOutputStream(16*1024);
map.compress(CompressFormat.JPEG, 80, bufferStream);
byte[] bytes = bufferStream.toByteArray();
ContentValues values = new ContentValues();
values.put("image", bytes);
convert the image byte array, using SQLiteDatabase class method or content provider as you like: 根据需要使用SQLiteDatabase类方法或内容提供程序转换图像字节数组:
public long insert (String table, String nullColumnHack, ContentValues values)
to insert to table, so it save the image to blob
. 插入表格,以便将图片保存到blob
。
and then: when you query the blob
data, you can create the image like this: 然后:当您查询blob
数据时,可以创建如下图像:
BitmapFactory.Options option2 = new BitmapFactory.Options();
option2.inPreferredConfig = Bitmap.Config.RGB_565;
// added for reducing the memory
option2.inDither = false;
option2.inPurgeable = true;
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, option2);
hope it can implement your request. 希望它可以实现您的请求。 -): -):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.