在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);
}
}