Interface Image

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  Image.Format
      An enumeration of the different formats in which image data may be produced, as indicated by dataFormat().
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      BufferedImage bitmap()
      Returns a BufferedImage for this Image that is ready to be drawn to a graphics context.
      Region bitmapBounds()
      Returns a Region whose width and height indicate that of the bitmap itself; its origin coordinates (Region.lx() and Region.by()) will always be 0, 0.
      byte[] data()
      Returns the data for this image, encoded according to the format indicated by dataFormat(); may return null if it is known that the image's data cannot be decoded without producing an exception.
      Image.Format dataFormat()
      Returns the format of the image data available from this image's data() method.
      String id()
      Returns the identifier associated with this image's bitmap data, guaranteed to be unique within the scope of its source document.
      • Methods inherited from interface com.snowtide.pdf.layout.Bounded

        bounds
    • Method Detail

      • bitmap

        BufferedImage bitmap()
                      throws IOException
        Returns a BufferedImage for this Image that is ready to be drawn to a graphics context. This method may return null if it is known that the image's data cannot be decoded without producing an exception, or if the image's dataFormat() is JPX / JPEG2000.

        Note for .NET developers

        The BufferedImage object returned from this method provides a .getBitmap() method that efficiently produces a .NET System.Drawing.Bitmap object. So, the pattern you'd typically use with bitmap() is e.g.:
         
         Page page = pdf.getPage(0);
         Image image = page.getImages().get(0).bitmap();
         if (image != null)
         {
             System.Drawing.Bitmap bmp = image.getBitmap();
             // ...code continues...    
         }
         
        Throws:
        IOException
      • bitmapBounds

        Region bitmapBounds()
        Returns a Region whose width and height indicate that of the bitmap itself; its origin coordinates (Region.lx() and Region.by()) will always be 0, 0.

        This does not represent the apparent bounds of the image when positioned on the page; use Bounded.bounds() for that.

      • data

        byte[] data()
             throws IOException
        Returns the data for this image, encoded according to the format indicated by dataFormat(); may return null if it is known that the image's data cannot be decoded without producing an exception.
        Throws:
        IOException
      • dataFormat

        Image.Format dataFormat()
        Returns the format of the image data available from this image's data() method.
      • id

        String id()
        Returns the identifier associated with this image's bitmap data, guaranteed to be unique within the scope of its source document.

        PDF documents can display the same bitmap multiple times; for example, an image that appears in the header of every page is very likely to be encoded once, and then just referenced at each point of usage. Though PDFxStream produces an different Image instance for each image shown in a PDF document, it:

        • ensures that images that reference the same encoded bitmap data will have the same id
        • retrieves and decodes that bitmap data only when necessary, i.e. when bitmap() and data() are called

        Together, this means that you can access all of the Images on a page or in a document, and gain easy, efficient access to their apparent Bounded.bounds() on the page, but then never decode the same bitmap data more than once: just track each Image's id, and reuse the data() or bitmap() objects for any duplicate ids you find.