1

我想使用从图库中选择或从相机捕获的 blob 将图像存储到 sqlite 数据库,并从数据库中取回这些图像以显示在列表视图或网格视图中。

4

1 回答 1

3

可以从 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);
于 2012-07-12T12:59:17.670 回答