Class RMImageData

java.lang.Object
com.inductiveautomation.rm.graphics.RMImageData
All Implemented Interfaces:
Cloneable

public class RMImageData extends Object implements Cloneable
This class manages image data. Each instance holds the raw image data and provides methods to return attributes of the decoded image.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    An interface for classes that can handle image reading for RMImageData.
    static interface 
    The preferred method for seeding RMImageData with an image source.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    RMImageData(Object aSource, int aPageIndex)
    Returns an image data for a given source and page index.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canRead(String anExt)
    Returns whether given extension is supported.
    Standard clone implementation.
    protected byte[]
    Creates bytes from the image (loaded from the source).
    protected void
    Creates decoded image bytes for the image.
    protected BufferedImage
    Creates a buffered image for image data.
    boolean
     
    int
    Color map support: returns the index of the transparent color in a color map image.
    int
    Returns the number of bits per pixel (derived from bits per sample and samples per pixel).
    int
    Returns the number of bits per sample (eg, 24 bit RGB image is 8 bits per sample).
    byte[]
    Returns the original bytes for the image (loaded from the source).
    byte[]
    Returns the decoded image bytes for the image.
    int
    Returns the number of bytes per row (derived from width and bits per pixel).
    byte[]
    Color map support: returns the bytes of color map from a color map image.
    int
    Returns the number of pixels vertically.
    Returns the buffered image for image data.
    Returns an image data loaded from aSource.
    getImageData(Object aSource, int aPageIndex)
    Returns an image data loaded from aSource.
    getImageDataBypassCache(Object aSource, int aPageIndex)
     
    double
    Returns the actual display height of the image in printer's points using the image DPI if available.
    double
    Returns the actual display width of the image in printer's points using the image DPI if available.
    Returns the name for the image (assigned from our hashCode).
    getPage(int aPage)
    Returns the image data for a successive page.
    int
    Returns the total number of pages for the image.
    int
    Returns the page index for the image.
    Returns the reader used to load the image.
    int
    Returns the number of samples per pixel (RGB=3, RGBA=4, GrayScale=1, etc.).
    Returns the original source for the image (byte[], File, InputStream or whatever).
    Returns the source URL, if loaded from URL.
    Returns the type for the image (one of gif, jpg, png, pdf, etc.).
    int
    Returns the number of pixels horizontally.
    boolean
    Color map support: returns whether color map image has a transparent color.
    boolean
    Returns whether image uses a color map.
    int
     
    boolean
    Returns whether the image is non-grayscale.
    boolean
    Returns whether the image was loaded successfully.
    void
    paint(RMShapePainter aPntr, double x, double y, double w, double h)
    Draws image data in given rect.
    void
    peekInflatedImage(Consumer<RMImageData> inflatedDataConsumer)
    Renders the backing BufferedImage and passes it to the supplied consumer.
    protected void
    Refreshes data from source.
    protected void
    setSource(Object aSource, int aPageIndex)
    Sets the source.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RMImageData

      protected RMImageData(WebURL url)
    • RMImageData

      protected RMImageData(Object aSource, int aPageIndex)
      Returns an image data for a given source and page index. Source can be an image or something that can provide bytes, but the preferred source is an RMImageData.ImageSupplier to prevent the backing image (or byte array) from being held in memory until report generation is completed which can quickly consume all available memory for large reports. Page index only applicable for multi-page image types, like PDF.
  • Method Details

    • getImageData

      public static RMImageData getImageData(Object aSource)
      Returns an image data loaded from aSource.
    • getImageData

      public static RMImageData getImageData(Object aSource, int aPageIndex)
      Returns an image data loaded from aSource. If image type supports multiple pages, page index can be specified.
    • getImageDataBypassCache

      public static RMImageData getImageDataBypassCache(Object aSource, int aPageIndex)
    • getSource

      public Object getSource()
      Returns the original source for the image (byte[], File, InputStream or whatever).
    • setSource

      protected void setSource(Object aSource, int aPageIndex)
      Sets the source. The preferred mechanisms for Images is RMImageData.ImageSupplier To prevent the image from being held in memory which can be catastrophic for large reports.
    • getSourceURL

      public WebURL getSourceURL()
      Returns the source URL, if loaded from URL.
    • refresh

      protected void refresh()
      Refreshes data from source.
    • getImage

      public BufferedImage getImage()
      Returns the buffered image for image data.
    • createImage

      protected BufferedImage createImage()
      Creates a buffered image for image data.
    • getBytes

      public byte[] getBytes()
      Returns the original bytes for the image (loaded from the source).
    • createBytes

      protected byte[] createBytes()
      Creates bytes from the image (loaded from the source).
    • getBytesDecoded

      public byte[] getBytesDecoded()
      Returns the decoded image bytes for the image.
    • createBytesDecoded

      protected void createBytesDecoded()
      Creates decoded image bytes for the image.
    • getName

      public String getName()
      Returns the name for the image (assigned from our hashCode).
    • getType

      public String getType()
      Returns the type for the image (one of gif, jpg, png, pdf, etc.).
    • getPageIndex

      public int getPageIndex()
      Returns the page index for the image.
    • getPageCount

      public int getPageCount()
      Returns the total number of pages for the image.
    • getWidth

      public int getWidth()
      Returns the number of pixels horizontally.
    • getHeight

      public int getHeight()
      Returns the number of pixels vertically.
    • getImageWidth

      public double getImageWidth()
      Returns the actual display width of the image in printer's points using the image DPI if available.
    • getImageHeight

      public double getImageHeight()
      Returns the actual display height of the image in printer's points using the image DPI if available.
    • isColor

      public boolean isColor()
      Returns whether the image is non-grayscale.
    • getSamplesPerPixel

      public int getSamplesPerPixel()
      Returns the number of samples per pixel (RGB=3, RGBA=4, GrayScale=1, etc.).
    • getBitsPerSample

      public int getBitsPerSample()
      Returns the number of bits per sample (eg, 24 bit RGB image is 8 bits per sample).
    • getBitsPerPixel

      public int getBitsPerPixel()
      Returns the number of bits per pixel (derived from bits per sample and samples per pixel).
    • getBytesPerRow

      public int getBytesPerRow()
      Returns the number of bytes per row (derived from width and bits per pixel).
    • hasAlpha

      public boolean hasAlpha()
      Color map support: returns whether color map image has a transparent color.
    • getAlphaColorIndex

      public int getAlphaColorIndex()
      Color map support: returns the index of the transparent color in a color map image.
    • hasColorMap

      public boolean hasColorMap()
      Returns whether image uses a color map.
    • getColorMap

      public byte[] getColorMap()
      Color map support: returns the bytes of color map from a color map image.
    • getPage

      public RMImageData getPage(int aPage)
      Returns the image data for a successive page.
    • getReader

      public RMImageData.ImageReader getReader()
      Returns the reader used to load the image.
    • isValid

      public boolean isValid()
      Returns whether the image was loaded successfully.
    • peekInflatedImage

      public void peekInflatedImage(Consumer<RMImageData> inflatedDataConsumer)
      Renders the backing BufferedImage and passes it to the supplied consumer. This is useful for capturing details like the image bounds etc for any implementations of drawing this image data on an exported report or similar. The image supplied to the consumer or the accompanying byte array(s) should not be held onto in memory. The supplied images are rendered with hi DPi's and can be very large, quickly consuming all available memory in larger reports. Note that EMPTY may be returned if there is no backing image (unlikely)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • clone

      public RMImageData clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • canRead

      public static boolean canRead(String anExt)
      Returns whether given extension is supported.
    • paint

      public void paint(RMShapePainter aPntr, double x, double y, double w, double h)
      Draws image data in given rect.