I have a project where a large number of tiff image files are concatenated together into one file (i.e. imagefile.img) and sent to us from another company. Accompanying this file is an index that give the "Image Starting Location" and the "Image length" in bytes is listed sequentially in a text file (i.e. ImageIndex.txt). For instance, two entries in the index file would looks something like this:
I would need to start at the beginning of the the image file read the first 13220 bytes and save those bytes as a .tif image. I would then need start at postion 13220 and read the next 12762 bytes and so on until all images are removed from the image file.
I assume I would need to use the Java Standard I/O libraries, but am not really sure since I have never done anything like this. What are my options for parsing through a large binary file and saving the tiff images contained therein as separate files?
Well it should already be encoded as a TIF to begin with so the file type is somewhat irrelevent. I think all you need to do is get a FileInputStream and pass the first x bytes to a FileOutputStream that is writing to the appropriate File. Then pass the next y bytes to a different FileOutputStream, etc.
Joined: Jun 01, 2006
Thanks, I think I understand, but I have not used the java.io library very much. I am a bit green and have mostly focused on Web and O/R stuff. I think I could figure this out on my own, but it would be helpful if you could post a snippet of code. (Perhaps I should have posted this in the beginners forum, if so, my apologies)
It's common fot .tiff files to contain multiple images. I suggest you check out the various javax.imageio packages. Reading such an image file is exactly what they were designed for! For example, javax.imageio.ImageReader has methods like:
Originally posted by Jeff Albertson: It's common fot .tiff files to contain multiple images. I suggest you check out the various javax.imageio packages. Reading such an image file is exactly what they were designed for! For example, javax.imageio.ImageReader has methods like:
He doesn't want to decode the image file and the standard javax.imageio package does not support TIF anyway, he'd have to go to JAI Image I/O for that. However, all of this is unnecessary for simply writing each x bytes to a different file.
See the JavaDoc for FileInputStream and FileOutputStream. You can read from a file into a byte array and write from the array to a file. If you have enough memory to make an array of exactly the number of bytes specified in the index you can do each file with a single read & write.