21

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

3 Answers 3

53

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.

Sign up to request clarification or add additional context in comments.

3 Comments

that's exactly what i did, but i was using drawable so I added a cast, but i don't think i need it. thanks for the help guys. thanks for the detailed explanation here
decodeByteArray method return null if the image could not be decoded; check your code that store to db.
this doesn't work on motorola! decodeByteArray says that I should send valid data it is not image data that I am sending. why? how to fix it?
4

Use BitmapFactory.decodeByteArray().

1 Comment

thx for the hint, i'll have a closer look and come back to you if I don't find.
4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.