使用 Java 将 DPI 和纸张尺寸信息存储在 JPEG 中
我有以下代码:
ImageIO.write(originalImage, OUTPUT_TYPE, resultOutput);
这是对以下 javax.imageio.ImageIO 方法的调用:
public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException
这会将原始 BMP 图像转换为 JGP 输出。是否可以在 JPEG 中存储 DPI 和纸张尺寸信息以帮助打印操作?
I have the following code:
ImageIO.write(originalImage, OUTPUT_TYPE, resultOutput);
This is an invocation of the following javax.imageio.ImageIO
method:
public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException
This turns an original BMP image into a JGP output. Is it possible to also store DPI and Paper Size information in the JPEG to aid in printing operations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了这篇关于在 PNG 文件上设置 DPI 的帖子。它指出您应该使用“metadata.mergeTree”来正确保存元数据。
考虑到这一点,这里有一些工作常规代码,它采用 BMP 文件并以任意 DPI 创建 JPG 文件:
在 OSX 的预览应用程序中对我来说工作得很好,Gimp 都报告生成的图像为 100 DPI。至于纸张大小...我想这是直接由 DPI 决定的?我找不到任何可以设置该特定值的 JPEG 属性。
I found this post for setting DPI on PNG Files. It pointed out that you should use 'metadata.mergeTree' to properly save your metadata.
With that in mind, here is some working groovy code that takes a BMP file and creates a JPG file at arbitrary DPI:
Worked fine for me in that OSX's Preview app and Gimp both reported that the resulting image was 100 DPI. As to Paper Size...I imagine this is directly determined by DPI? I couldn't find any JPEG property that would set that particular value.
您可以考虑使用 Commons Sanselan 而不是 ImageIO 来完成此任务。
有关详细信息,请参阅 http://commons.apache.org/sanselan/whysanselan.html 。
You may consider using Commons Sanselan, instead of ImageIO for this task.
See http://commons.apache.org/sanselan/whysanselan.html for more info.