简体   繁体   中英

Is it possible to control the image quality of png encoding on Android?

I'm trying to convert a bitmap to PNG with

bitmap.compress(Bitmap.CompressFormat.PNG, quality, outStream);

and then share the file. According to the documentation quality parameter is ignored for PNG format.

Can I control the image quality while converting bitmap to PNG, despite it's a lossless format?

Or should I go with JPEG, taking into account that the image I want to share doesn't have any transparency. On the other hand, some part of the image (about 30-40%) filled with the same color, which is PNG works well with, as far as I know.

PNG doesn't have a quality factor. PNG compression is lossless (ie, quality is always 100%).

You can, however, reduce the image quality before handing it to the compressor, by doing thing such as reducing the number of colors and transparency levels, not using anti-aliasing, etc, to make the image data more compressible.

You can also recompress the PNG file afterwards with a separate optimizer such as pngquant, pngcrush, imagemagick/graphicsmagick, zopflipng, or optipng.

Note that imagemagick/graphicsmagick do have a "quality" value for PNG compression, but it has a different meaning than for JPEG files (higher PNG "quality" generally means better compression but no change in image appearance).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM