Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 686
Sephy Avatar asked Apr 26 '10 15:04

Sephy


3 Answers

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.

like image 127
systempuntoout Avatar answered Sep 21 '22 13:09

systempuntoout


Use BitmapFactory.decodeByteArray().

like image 29
Dan Lew Avatar answered Sep 24 '22 13:09

Dan Lew


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);
like image 33
J.S.R - Silicornio Avatar answered Sep 23 '22 13:09

J.S.R - Silicornio