I want to compress bitmap , but I don't want to change the width and heigh.
My bitmap type is .PNG, So bitmap.compress()
does not have any effect. I need a method to resolve it.
Asked
Active
Viewed 794 times
3

W4R10CK
- 5,502
- 2
- 19
- 30

Crazy Zhang
- 53
- 7
-
check this link.http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966 – dipali Jan 11 '17 at 04:30
-
I can't change image width and height , they are important to me,I have to compress the picture without changing the width and height @SadiqMdAsif – Crazy Zhang Jan 11 '17 at 06:00
-
`BitmapFactory.decodeStream(new FileInputStream(f), null, o);` method change the bitmap width and height.@dipali – Crazy Zhang Jan 11 '17 at 06:06
-
It's not possible. The quality parameter of the Bitmap.compress function is ignored in the case of PNG, it's already as small as possible. Realistically, if you could losslessly compress a PNG to a smaller file size without changing the width or height, don't you think it would already do that by default? In some image editing software e.g. GIMP you can adjust the compression level of a PNG to get a smaller size at the expense of slower encoding/decoding, but to do that on Android you would need a PNG library. – samgak Jan 11 '17 at 06:20
-
Thank you,I know my problem is almost impossible to reslove by my way, I only want to try to find the answer. I try to `opt.inSampleSize = 2;Bitmap result = BitmapFactory.decodeStream(isBm, null, opt);` and then `matrixs.setScale(2f, 2f); Bitmap result2 = Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), matrixs, true);`The bitmap width not change and the size has been compressed, but scaled back@samgak – Crazy Zhang Jan 11 '17 at 06:38
1 Answers
0
If you want to reduce image size or bitmap bytes count, here is good library on GitHub:

Nikola
- 109
- 1
- 3
- 13