• Post Reply Bookmark Topic Watch Topic
  • New Topic

tiff file - how to verify it and get image details?  RSS feed

 
Bucsie Dusca
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My app receives image files from the user. I must verify that the file is indeed a tiff file, and check its compression. How can I do that?
I have read JAI docs, image I/O lib docs but none of them gave me an answer. It was easy to transform to jpeg, display it in the interface, image manipulation stuff, but a simple query as this - I just can't figure out.

Any help is highly appreciated
Thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To check whether a file is a TIFF look at the first 4 bytes. Wikipedia describes what they should contain. Note that there may be differences depending on the byte order.

What do you mean by "check its compression"?
 
Bucsie Dusca
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean like geting something like in the table here:

http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/imageio/plugins/tiff/TIFFImageWriteParam.html

i'm thinking (probably simplistic) there should be such a thing like image.getType() image.getColorDepth() (b/w, grayscale, 8b ....)

i mean it's not safe to assume that if i read a *.tiff file (or maybe I just get a bufferedImage, or just a byte[]) it is actually a tiff and not a .bmp in a .tiff's clothing. and an imaging api should provide such simple methods (if it takes just reading 4 bytes).
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, once it's in memory, it's a BufferedImage. So anything TIFF-specific is lost.

The closest I can think of is the ImageJ library. Its ij.io.TiffDecoder can create an ij.io.FileInfo object which has lots of information like color depth, image size, number of images, compression method etc. It doesn't support all possible compression methods, though.

If you feel really adventurous, source code that can read a wider range of TIFF images can be found here.
 
Bucsie Dusca
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!