2

Now I have to do some processing(such as read/save) with some .tif images, but it seems like I can not read or write the images by java. Is there any library can help me for that? And How to used it to read or save the images? Thanks for your answer.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
zhao0800
  • 23
  • 1
  • 1
  • 3
  • 3
    Welcome to Stack Overflow! We encourage you to [research your questions](http://stackoverflow.com/questions/how-to-ask). If you've [tried something already](http://whathaveyoutried.com/), please add it to the question - if not, research and attempt your question first, and then come back. –  Oct 18 '12 at 07:57

4 Answers4

4

I guess you will need to use the JAI (Java advances imaging package), take a look at this, and see this example

Community
  • 1
  • 1
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • For the file-types supported for read by `ImageIO` by ***default***, see [`ImageIO.getReaderFileSuffixes()`](http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#getReaderFileSuffixes%28%29) a standard JRE will not include TIFF. +1 for link to JAI examples. – Andrew Thompson Oct 18 '12 at 08:09
4

Java Advanced Imaging provides support for TIFF out of the box. Alternately add a Service Provider Interface Jar for TIFF on the run-time class-path of the app. and ImageIO will be able to deal with them (load them at least, it probably won't provide support for 'multi-page' TIFF writing).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    [jai-imageio](http://www.oracle.com/technetwork/java/current-142188.html), look to the second section of downloads called **Java Advanced Imaging-Image I/O Tools Downloads**...don't forget to accept the answer when you can ;) – MadProgrammer Oct 18 '12 at 08:11
  • @MadProgrammer Good link. I've fleshed out the JAI Wiki (linked above). With that link and two others related to JAI (FAQ & Java docs.). – Andrew Thompson Oct 18 '12 at 08:20
  • @AndrewThompson Can't believe it took me so long to find it :P – MadProgrammer Oct 18 '12 at 08:24
  • 1
    @Mad *"Can't believe it took me so long to find it"* DYM at the Oracle site? I am not surprised at all. I gave up using Sun's search engine long ago (I don't think Oracle has improved it much, but have not checked). Instead I go to a major search engine who shall remain nameless and search for hits within domain `oracle.com`. ;) – Andrew Thompson Oct 18 '12 at 08:28
  • 1
    @AndrewThompson I found the links on from another question on SO actually (using unnamed search engine) :P – MadProgrammer Oct 18 '12 at 08:29
2

Java supports reading and writing jpeg, gif and png by default, using ImageIO. In order to read tiff images, you must use a JAI plugin called jai_imageio.jar. You just put this jar in the classpath and you will be able to read tiff images.

Dan D.
  • 32,246
  • 5
  • 63
  • 79
1

used jai not working now, can't get "com.sun.image". But found another package that works - jdeli. It has a class TiffDecoder, which can be used to decode(read) tiff images with alpha channel to a Buffered image. Then you can write that image using ImageIO.write

Sujin S
  • 21
  • 3