Sephy
Sephy

Reputation: 50402

byte[] to image android

My issue is as follows : I have stored a few pictures into the sqlite database, using the blob format, which seems to work ok. now i want to get my pictures out of the DB and put then back into images... to complicate the matter, their format is variable (png, jpg, maybe something else, im not sure) Is there a way of doing so in android?

thank you

Upvotes: 21

Views: 49040

Answers (3)

J.S.R - Silicornio
J.S.R - Silicornio

Reputation: 1141

I prefer to convert the array of bytes to Drawable directly. It is the best format to use in Android. Bitmaps generated leaks in the past.

Drawable d = Drawable.createFromStream(new ByteArrayInputStream(ARRAY_BYTES), null);

Upvotes: 4

systempuntoout
systempuntoout

Reputation: 74104

Use BitmapFactory.decodeByteArray() method:

byte[] blob=c.getBlob("yourcolumnname");
Bitmap bmp=BitmapFactory.decodeByteArray(blob,0,blob.length);
ImageView image=new ImageView(this);
image.setImageBitmap(bmp);

Look at this thread too.

Upvotes: 53

Dan Lew
Dan Lew

Reputation: 87430

Use BitmapFactory.decodeByteArray().

Upvotes: 4

Related Questions