• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic