如何在数据库中保存图像?

时间:2013-02-23 15:21:34

标签: android database image

我有数据库,其中我有3列(第一个Id,第二个标题String,第三个图像int)。 DB喜欢带照片的联系人列表。

ContentValues cv = new ContentValues();
cv.put(COLUMN_TITLE, "John");
cv.put(COLUMN_IMG_OUTSIDE, R.drawable.john_photo);
db.insert(DB_TABLE, null, cv));

然后使用SimpleCursorAdapter我从名称及其照片中填写列表

SimpleCursorAdapter scAdapter;
String[] from = new String[] { DataBase.COLUMN_IMG_OUTSIDE,DataBase.COLUMN_TITLE};
int[] to = new int[] { R.id.img, R.id.text1, };

cursor = db.getAll();
startManagingCursor(cursor);

scAdapter = new SimpleCursorAdapter(ListOfItems.this, R.layout.list, cursor, from, to);
listView.setAdapter(scAdapter);

一切正常,但是当我想将记录添加到数据库并从Galery中选择一张图片时,我不知道如何将其保存在数据库中。我想我可以保存文件路径,如String path = "/sdcard/DCIM/Camera/IMG20130222_008.jpg";但是当我填充列表时会出现问题,因为在DB映像中保存就像整数值一样。抱歉我的英语=(

1 个答案:

答案 0 :(得分:1)

也许您应该尝试将整个图像保存为db作为blob?

请参阅Android How to save camera images in database and display another activity in list view?

在这种情况下,你必须编写自己的CursorAdapter,然后看到这个 Images in SimpleCursorAdapter

相关问题