Java 图像质量 (JPEG)
是否可以获得现有图像的当前质量?
我想加载 JPEG 并再次保存,而不改变质量和 DPI。 (我需要在保存之前进行一些像素操作)
Is it possible to get the current quality of an existing image?
I want to load a JPEG and save it again without any change in quality and DPI. (I need to do some pixel manipulation before saving)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JPEG 是一种有损格式。
直接的方法是,读取图像,做你需要做的事情,重新编码图像,会导致图像稍微恶化。
也就是说,如果可以的话,那么您需要知道 JPEG 编码中质量的工作方式是确定要保留多少有关对比度的信息。质量越差,过渡就越不清晰。换句话说,这不是JPEG文件中包含的单个设置,而是确定保存的图像数据的数量的设置。
您可以做的是,最终图像的大小需要与原始图像的大小大致相同。然后,您可以以不同的质量设置对结果进行编码,并选择能够提供您想要的图像尺寸的设置。
JPEG is a lossy format.
The direct way to do this, read the image, do what you need to do, reencode the image, will result in the image being slightly deteriorated.
That said, if that is fine, then you need to know that the way that quality works in JPEG encoding, is to determine how much information to keep about contrast. The less quality, the less sharp a transition you can have. In other words, this is not a single setting enclosed in the JPEG-file, but a setting determining the number of image data saved.
What you can do is to say that the final image need to be around the same size as the original. You can then encode the result at different quality settings and choose the one giving the image size you want.