MichaelP
MichaelP

Reputation: 2781

What is wrong with saving image into sqlite database?

I want to write an image into database as blob type. But when i load this image from database, it's different from source image. I write source image into database as follow:

  ByteArrayOutputStream bs = new ByteArrayOutputStream();
Bitmap medBmp = BitmapFactory.decodeStream(this.getResources().openRawResource(R.drawable.source_image));
            medBmp.compress(Bitmap.CompressFormat.JPEG, 100, bs);
            initialValues.put(IMAGE_COL,bs.toByteArray());  

And here are images

source image: enter image description here

Image is loaded from database enter image description here

The background of source image is transparent, but the image is loaded from db has background in black.why are they different?What is wrong with my code?

Please help me out, thanks you so much.

Upvotes: 1

Views: 330

Answers (1)

Kumar Bibek
Kumar Bibek

Reputation: 9117

You are saving the image as JPEG, and JPEG's don't support transparency. So, you would get that black background. Try using PNG format.

Upvotes: 7

Related Questions