我想使用从图库中选择或从相机捕获的 blob 将图像存储到 sqlite 数据库,并从数据库中取回这些图像以显示在 ListView 或 GridView 中。
最佳答案
可以存储图像并从 sqlite 数据库中检索图像。
存储代码
// Convert your bitmap to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] bytes = out.toByteArray();
ContentValues cv = new ContentValues();
cv.put("IMAGE", bytes);
获取它的代码
// Use Cursor to retrieve the image
byte[] bytes = cursor.getBlob(column_index);
ByteArrayInputStream input = new ByteArrayInputStream(bytes);
Bitmap bit = BitmapFactory.decodeStream(input);
关于android - 如何将图像保存到从图库中选择的 sqlite 数据库或从相机捕获到 sqlite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11451912/