无损压缩png_由于PNG格式具有压缩参数,它是否无损?

无损压缩png

无损压缩png

how-is-the-png-format-lossless-since-it-has-a-compression-parameter-00

The PNG format is supposed to be a lossless format, but when you save an image as a PNG file, you are asked to choose a compression level. Does this mean that the PNG format is actually not lossless after all? Today’s SuperUser Q&A post helps clear up the confusion for a curious reader.

PNG格式应该是无损格式,但是将图像另存为PNG文件时,会要求您选择压缩级别。 这是否意味着PNG格式实际上并不是无损的? 今天的“超级用户”问答页面有助于消除好奇读者的困惑。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

问题 (The Question)

SuperUser reader pkout wants to know if the quality of a PNG image is affected by the compression level chosen:

SuperUser阅读器pkout想要知道PNG图像的质量是否受所选压缩级别的影响:

As I understand it, PNG files use lossless compression. However, when I am using an image editor such as Gimp and try to save an image as a PNG file, it asks for a compression level ranging between 0 and 9.

据我了解,PNG文件使用无损压缩。 但是,当我使用图像编辑器(例如Gimp)并尝试将图像另存为PNG文件时,它要求的压缩级别为0到9。

If it has a compression parameter that affects the visual precision of the compressed image, how is PNG lossless then? Can someone please explain this to me? Do I get lossless behavior only when I set the compression level to 9?

如果压缩参数会影响压缩图像的视觉精度,那么PNG如何无损? 有人可以向我解释一下吗? 仅当将压缩级别设置为9时,我才会获得无损行为吗?

Is there a difference in the quality of the image depending on the compression level you choose?

根据您选择的压缩级别,图像质量是否有所不同?

答案 (The Answer)

SuperUser contributors LordNeckbeard and jjlin have the answer for us. First up, LordNeckbeard:

超级用户贡献者LordNeckbeard和jjlin为我们找到了答案。 首先,领颈长:

PNG is Compressed, but Lossless

PNG已压缩,但无损

The compression level is a trade-off between file size and encoding/decoding speed. To overly generalize, even non-image formats such as FLAC have similar concepts.

压缩级别是文件大小和编码/解码速度之间的权衡。 为了过度概括,甚至非图像格式(例如FLAC)也具有类似的概念。

Different Compression Levels, Same Decoded Output

不同的压缩级别,相同的解码输出

Although the file sizes are different due the the different compression levels, the actual decoded output will be identical. You can compare the MD5 hashes of the decoded outputs with ffmpeg using the MD5 muxer. This is best shown with some examples.

尽管由于压缩级别不同,文件大小也不同,但是实际的解码输出将是相同的。 您可以使用MD5多路复用器将解码输出的MD5哈希与ffmpeg进行比较。 最好通过一些示例来说明。

Create PNG Files

创建PNG文件

how-is-the-png-format-lossless-since-it-has-a-compression-parameter-01
  • By default, ffmpeg will use -compression_level 100 for PNG output.

    默认情况下,ffmpeg将使用-compression_level 100进行PNG输出。
  • A quick, sloppy test showed that 100 (the highest compression level) took roughly three times longer to encode and five times longer to decode than 0 (the lowest compression level) in this example.

    快速,草率的测试表明,在此示例中,与0(最低压缩级别)相比,100(最高压缩级别)花费的编码时间和解码时间分别约为3倍和5倍。

Compare File Size

比较文件大小

how-is-the-png-format-lossless-since-it-has-a-compression-parameter-02

Decode the PNG Files and Show MD5 Hashes

解码PNG文件并显示MD5哈希

how-is-the-png-format-lossless-since-it-has-a-compression-parameter-03

Since both hashes are the same, you can be assured that the decoded outputs (the uncompressed raw files) are exactly the same.

由于两个哈希值相同,因此可以确保解码后的输出(未压缩的原始文件)完全相同。

Followed by the answer from jjlin:

随后是jjlin的回答:

PNG is lossless. GIMP is most likely not using the best choice of wording in this case.

PNG是无损的。 在这种情况下,GIMP很可能没有使用最佳的措词选择。

Think of it as quality of compression or level of compression. With lower compression, you get a bigger file, but it takes less time to produce, whereas with higher compression, you get a smaller file that takes longer to produce.

将其视为压缩质量压缩 级别 。 使用较低的压缩率,您可以获得较大的文件,但是生成时间较短,而使用较高的压缩率,则文件较小,而生成时间更长。

Typically you get diminishing returns, i.e. not as much decrease in size compared to the increase in time it takes when going up to the highest compression levels, but it is up to you.

通常情况下,您得到的收益递减,即与达到最高压缩级别所需的时间增加相比,大小的减少不会那么多,但完全取决于您。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/203979/is-the-png-format-lossless-since-it-has-a-compression-parameter/

无损压缩png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值