Problem saving bitmap

All your problems with Audio, Video and Images.

Problem saving bitmap

Postby rkarthik » Tue Aug 25, 2009 10:15 am

Hi Guys,

Im trying to read images into bitmap doing some changes to it and saving them back. But while saving if i use the compress format as JPEG there is a sever loss in quality where as for PNG it is fine. Can you please help me out.. The below is what i am doing.

On opening the file,

mBitmap = BitmapFactory.decodeStream(concontentresolver.openInputStream
//to create a mutable bitmap out of it
mBitmap = Bitmap.createScaledBitmap(mBitmap,mBitmap.getwidth
(),mBitmap.getHeight(), true);
//also tried, for making the bitmap mutable
//mBitmap =mBitmap.copy(Config.ARGB_8888, true);

After i make changes to the bitmap i try to save it by,

OutputStream out = getContentResolver().openOutputStream(file);
if (type.equalsIgnoreCase("image/jpeg")) {
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
} else {
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

But what i can see is that when i save it in a jpeg format there is a
loss in quality, and when i open a jpeg file for 3-4 time and save it,
the image is totally blurred. And the size of the
jpeg image file increases each time i save the image.
When i save it using Bitmap.CompressFormat.PNG the image is saved
properly, please guide me.

Is there any process that i have to do while opening a jpeg file and
writing it to a bitmap?

Junior Developer
Junior Developer
Posts: 17
Joined: Wed Jan 14, 2009 11:40 am


Postby zoalord12 » Wed Aug 26, 2009 10:15 am

why are you doing this
Bitmap.createScaledBitmap(mBitmap,mBitmap.getwidth(),mBitmap.getHeight(), true);

the true at the end means that the image is being filtered. and if you rescale to a bigger size , it is going to loose quality.

in your case, this line of code is useless since you are resizing to the height and width of the already loaded image ..
Posts: 7
Joined: Mon Aug 17, 2009 1:43 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 2 guests