如何保存位图数据库? [英] How to save bitmap in database?
本文介绍了如何保存位图数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何保存一个位图数据库。我在DB作为创建的表:
I want to know how to save a bitmap in database. I created table in db as:
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE " + TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT,image BLOB)");
}
我的问题是我不能够插入图像。请告诉我其中的格式,我需要插入图像。
My problem is I am not able to insert the image. Please tell me in which format I need to insert the image.
推荐答案
如果您有位图图像,那么你可以做以下。
If you have Bitmap image then you can do following.
Bitmap photo = <Your image>
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bArray = bos.toByteArray();
然后就可以使用以下方式将数据保存在表中。
Then you can save data in table using following way.
db = YourDBHelper.getInstance(ctx).getWritableDatabase();
ContentValues values = new ContentValues();
values.put("image", bArray);
db.insert(TABLE_NAME , null, values);
这篇关于如何保存位图数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文