如何将多个 png 图像转换为单个 tiff 文件
我有一个由 png 格式的多个图像组成的字节数组。 我必须将其转换为 tiff 文件,然后转换为相应的字节数组。 该 tiff 文件将保存多个图像。
我已经搜索了很多,但还没有成功。 问题是。 我只能用java来做这个!! :) 任何人都可以提供有关我的问题的一些见解吗?
我不会从 ImageMagick 等中受益,因为我有一个服务器组件来处理此转换,然后将其作为 tiff 保存在后端。 客户端给了我一个字节数组,它将转换为 png 图像。
I have a byte array of several images in the png format. I have to convert this to a tiff file and then into the corresponding byte array. This tiff file will hold multiple images.
I have searced a lot, but I haven't been successful.
The catch is. i have to do this in java only!! :)
Can anyone provide some insight as regards my issue?
I wont benefit from ImageMagick etc, because i have a server component that handles this conversion, and then saves it in the backend as a tiff.
The client gies me a byte array which would translate into a png image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
下面是解决方案。
Below is the solution.
JMagick 库是一个 ImageMagick 的 Java 接口,并且很可能是你要。
The JMagick library is a Java interface to ImageMagick, and is likely to be what you want.
您是否尝试以编程方式执行此操作? 您可能想看看 ImageMagick (http://www.imagemagick.org/script/index.php) php)
如果您正在编写某种 shell 脚本(bash、批处理),您可以调用
convert
命令(该命令是该包的一部分)。否则, ImageMagick 可通过库(C、perl 等)获得,您可以尝试将其链接到您的程序中。Are you trying to do this programatically? You might want to look at ImageMagick (http://www.imagemagick.org/script/index.php)
If you are writing a shell script of some sort (bash, batch) you can invoke the
convert
command (which is part of that package.) Otherwise, all of the functionality of ImageMagick is available through libraries (C, perl, etc) which you can try linking in with your program.我已经使用 Ghostscript 创建多页 PDF 文件,您也许可以做类似的事情。 我的特定应用程序有许多 JPG 文件,我将它们传递给 Windows 上的 Ghostscript 命令行调用来创建多页 PDF。
如果我这样做,我会首先将 png 文件写入磁盘。 接下来使用 Ghostscript 通过将所有 PNG 文件作为输入来创建多页 ps 文件,并输出到单个 PostScript 文档。 最后,使用ps2tif之类的东西进行最终的转换。 您可以通过以编程方式编写批处理脚本来自动化该过程,也可以让您的应用程序直接调用命令行应用程序。
这在 Unix/Linux 环境中可能是最容易完成的,但在 Win32 上使用相同的工具也是可行的。
I've used ghostscript to create multi-page PDF files, you might be able to do something similar. My particular application had a number of JPG files that I passed to a command line call to ghostscript on windows to create a multi-page PDF.
If I were doing this, I would start by writing the png files to disk. Next use ghostscript to create a multi-page ps file by taking all the PNG files as input, and outputing to a sinlge PostScript document. Finally, use something like ps2tif to do the final conversion. You could either automate the process by programmatically writing out a batch script or just having your app call the command line apps directly.
This is probably easiest to do in a Unix/Linux environment, but it's doable on Win32 with the same tools.
您应该使用 JAI(Java 成像 API)。 它能够读取/写入 PNG,并且至少能够读取 TIFF(也应该支持写入)。
http://java.sun.com/products/java-media/ jai/iio.html
如果不支持写入,请使用 Lizard 的 Tiff Java 库 (http:// /www.lizardworks.com/libs.html)
在此主题中,您可以了解如何将多个文件合并到一个 TIFF 中。 发帖人在更改 TIFF 元数据时遇到问题,但这不会影响您的问题。
http://forums.java.net/jive/thread。 jspa?messageID=244190&tstart=0
You should use the JAI (Java Imaging API). It is capable of reading/writing PNG's and at least capable of reading TIFF (writing should be supported too).
http://java.sun.com/products/java-media/jai/iio.html
If writing is not supported use Lizard's Tiff Library for Java (http://www.lizardworks.com/libs.html)
In this thread you can find how to merge multiple files into one TIFF. The poster has Problems changing the TIFF metadata but this should not affect your Problem.
http://forums.java.net/jive/thread.jspa?messageID=244190&tstart=0