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.
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.
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.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
The JMagick library is a Java interface to ImageMagick, and is likely to be what you want.
Below is the solution.