【问题标题】:BitmapFactory.decodeStream(inputStream) returns null when retrieving image from SQLite从 SQLite 检索图像时,BitmapFactory.decodeStream(inputStream) 返回 null
【发布时间】:2017-03-10 07:13:30
【问题描述】:

我的 SQLite 表中有一个 BLOB 类型列,并且正在将可绘制图像的字节 [] 保存到其中。现在,在检索时,我正在使用光标访问 blob

cursor.getBlob(cursor.getColumnIndex(SQLiteHelper.col_product_image))

然后使用下面的代码来显示上面代码中检索到的byte[]

ByteArrayInputStream inputStream = new ByteArrayInputStream(bb);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            iv.setImageBitmap(bitmap);

但图像视图中没有显示任何内容,因为BitmapFactory.decodeStream(inputStream); 为空。

bb的值为[91, 66, 64, 52, 51, 54, 102, 51, 53, 51, 48, 0]

救命!

【问题讨论】:

  • bb ???什么是bb?您应该显示完整的可重现代码。
  • saving the byte[] of an image f 检查你放入了多少字节以及你从一开始就取出了多少。

标签: android arrays image sqlite blob


【解决方案1】:

您的二进制数据存储不正确。

字节

91, 66, 64, 52, 51, 54, 102, 51, 53, 51, 48, 0

映射到字符串

[B@436f3530

看起来像byte[]toString() 输出,而不是字节数组本身。

此外,Android sqlite 不适用于存储大型(2MB 或更多)二进制数据,例如图像。您最好将图像保存到文件系统,并将路径存储在数据库中。

【讨论】:

  • 你能给我一个参考链接吗?
猜你喜欢
  • 2011-08-21
  • 2012-11-24
  • 2011-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-31
  • 2013-09-11
  • 1970-01-01
相关资源
最近更新 更多