Android Question PNG Bit Depth

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Is there anyway to set the Bit Depth on a PNG?

I have bitmap I want to write out to a PNG file.

PNG files allow setting the Bit Depth (my Graphic editor Paint.Net) allows Auto-detect, 32-bit, 24-bit and 8-bit.

I only need 8-bit quality when writing this bitmap out.

I am currently writing it out using WriteToStream(Out, 100, "PNG")
I have tried different numbers other then 100 and they do nothing to the file size (only on JPEG)

Using the above the file size is 88kb
If I open the file in Paint.Net and then do a File Save As and choose the 8-Bit for Bit Depth the file size becomes 61kb

I know not much but I am going to send this file as an Email attachment and want to keep it as small as possible.

Thanks

BobVal

PS: Tried using BitmapExtended to createScaledBitmap and all the way down to 40% (file looks ugly when viewed) the savings are only about 7kb.
 

Informatix

Expert
Licensed User
Longtime User
I don't think that is possible. I can't see any function or option allowing to do that in the Android API. Note that some libraries, like libGDX, cannot display properly PNG with 24 or 8-bit quality.

PS: I can't see the relation between CreateScaledBitmap and your question. CreateScaledBitmap is intended to change the dimensions of your bitmap. If you want to have the smallest size on disk with decent quality, use JPG with a high quality setting (e.g. 90).
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I tried JPEG and it seems to make higher file sizes (just tried and it is 84.9kb for PNG and 279.2kb for JPEG at 90%) at 50% the JPG file is 154.2kb

Knocked my socks off, I thought the JPEG file would be a lot smaller.

But I might be getting too picky - less than 100kb should be fine. Just always trying to size.

Thanks

BobVal
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…