• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
Slime does not pay. Always keep your tiny ad dry.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic