【发布时间】:2015-04-07 22:35:01
【问题描述】:
在 android 中,我试图使用糖 ORM 将图像保存到本地 sqlite 数据库,然后将其加载到其他地方。但图像不会显示,我不断收到:
image header:[5b 42 40 32 30 36 39 38], stream len = 12, read byte count = 8, valid byte count = 8, [[B@20698]
--- SkImageDecoder::Factory returned null
保存图片:
byte[] image = Utilities.getBytes(pImage);
Log.e("TAG", String.valueOf(image));
Product product = new Product(pName, pBrand, pExpireDate, image);
product.save();
加载:
Log.e("TAG", String.valueOf(product1.image));
Bitmap image = Utilities.getImage(product1.image);
pImage.setImageBitmap(image);
实用程序类:
public class Utilities {
public static byte[] getBytes(Bitmap bitmap)
{
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100, stream);
return stream.toByteArray();
}
public static Bitmap getImage(byte[] image)
{
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
}
【问题讨论】:
-
试试
Utilities.getImage( Utilities.getBytes(img))看看效果好不好 -
Getbytes 需要一个位图而不是一个字节数组
-
我的意思是用这一行,看看输出的是不是普通的位图。
标签: android sqlite bytearray android-imageview sugarorm