简体   繁体   English

是否可以在Android上控制png编码的图像质量?

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

I'm trying to convert a bitmap to PNG with 我正在尝试将位图转换为PNG

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

and then share the file. 然后共享文件。 According to the documentation quality parameter is ignored for PNG format. 根据文档,对于PNG格式, quality参数将被忽略。

Can I control the image quality while converting bitmap to PNG, despite it's a lossless format? 尽管位图是无损格式,但是在将位图转换为PNG时可以控制图像质量吗?

Or should I go with JPEG, taking into account that the image I want to share doesn't have any transparency. 还是考虑到我要共享的图像没有透明度,我应该使用JPEG。 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. 另一方面,据我所知,图像的某些部分(大约30-40%)填充了相同的颜色,即PNG。

PNG doesn't have a quality factor. PNG没有品质因数。 PNG compression is lossless (ie, quality is always 100%). PNG压缩是无损的(即质量始终为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. 之后,您还可以使用单独的优化程序(例如pngquant,pngcrush,imagemagick / graphicsmagick,zopflipng或optipng)重新压缩PNG文件。

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). 请注意,imagemagick / graphicsmagick对于PNG压缩确实具有“质量”值,但与JPEG文件具有不同的含义(较高的PNG“质量”通常表示压缩效果更好,但图像外观没有变化)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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