O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Get the image readers by format name, which is tiff for TIFF images
         Iterator iterator = ImageIO.getImageReadersByFormatName("tiff");
  1. Get the first ImageReader object from the image readers obtained in the previous step:
         ImageReader reader = (ImageReader) iterator.next();
  1. Create a FileImageInputStream object for the sample.tif image:
        try(ImageInputStream is = 
                 new FileImageInputStream(new File("sample.tif"))) {
          //image reading code here.
        } catch (Exception ex){
          //exception handling
        }
  1. Use the reader obtained to read the image file:
         reader.setInput(is, false, true);
  1. Let's get some attributes, such as the number of images, width, and height, just to confirm that we have really read the image:
 System.out.println("Number ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required