如何在java中使jpeg无损?
有人可以告诉我如何在java中使用无损
压缩编写'jpeg'文件吗?
我使用下面的代码读取字节来编辑字节
WritableRaster raster = image.getRaster();
DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
,并且我需要将字节再次写入为“jpeg”文件,而不用有损
进行压缩。
Is there someone that can tell me how to write 'jpeg' file using lossless
compression in java?
I read the bytes using the code below to edit the bytes
WritableRaster raster = image.getRaster();
DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
And I need to write again the bytes as 'jpeg' file without compressing in lossy
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JAI 包提供了保存“无损 JPEG”格式的能力。将压缩类型设置为 JPEG-LS 或 JPEG-LOSSLESS 取决于您想要什么变体。
不过,我不确定您是否真的想要无损 JPEG。它是一种独立的格式,与普通的 JPEG 格式没有太大关系。一般来说,它并没有得到很好的支持;对于无损图像存储,您通常最好使用 PNG 之类的东西。
如果您需要进行无损图像转码(即在不干扰 DCT 矩阵边界的情况下可以执行的一组裁剪和旋转操作),您通常会使用
jpegtran
命令来完成,因为没有据我所知,目前 Java 绑定到了 IJG 库。预计到达时间:
我自己没有尝试过(下面的代码未经测试),但它应该是对
setCompressionType
的直接调用。 (当然,Java 中的“直接”仍然意味着通过迷宫般的曲折小对象来设置其他地方的简单开关:)JPEG-LS 是较新的无损 JPEG 标准。它的压缩程度超过了原始的 JPEG-LOSSLESS 标准,但支持更差。大多数支持 JPEG 的应用程序将无法对它们执行任何操作。
The JAI package offers the ability to save “lossless JPEG” formats. Set compresion type to JPEG-LS or JPEG-LOSSLESS depending on what variant you want.
I'm not sure you really want lossless-JPEG though. It's a separate format that's not really much to do with the normal JPEG format. It is not, in general, very well-supported; for lossless image storage you are typically better off with something like PNG.
If you need to do lossless image transcoding (ie the set of cropping and rotation operations you can do without disturbing the boundaries of the DCT matrices), you would generally do it with the
jpegtran
command, as there's not currently a Java binding to the IJG library as far as I know.ETA:
I've not tried it myself (code below is untested), but it should be a straightforward call to
setCompressionType
. (Of course ‘straightforward’ in Java still means negotiating a maze of twisty little objects to set what would be a simple switch anywhere else:)JPEG-LS is the newer lossless JPEG standard. It compresses more than the original JPEG-LOSSLESS standard but support is even worse. Most applications that support JPEG will not be able to do anything with these.