mardi 7 avril 2015

Image won't show when loaded from sqlite database

In android im trying to save an image to an local sqlite databate with sugar ORM and then load it somewhere else. but the image won't show and i keep getting:



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


To save the image:



byte[] image = Utilities.getBytes(pImage);
Log.e("TAG", String.valueOf(image));
Product product = new Product(pName, pBrand, pExpireDate, image);
product.save();


To load:



Log.e("TAG", String.valueOf(product1.image));
Bitmap image = Utilities.getImage(product1.image);
pImage.setImageBitmap(image);


Utilities class:



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

}

Aucun commentaire:

Enregistrer un commentaire