Class PixelImage


  • public class PixelImage
    extends java.lang.Object
    Aggregates information for painting a colour-mapped image.

    Some utility methods are provided for generating suitable colour models.

    Since:
    4 Sep 2015
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      PixelImage​(java.awt.Dimension size, int[] pixels, java.awt.image.IndexColorModel colorModel)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.image.IndexColorModel createColorModel​(Shader shader, boolean zeroTransparent)
      Returns an indexed colour model whose entries range from one end to the other of a given shader object.
      static java.awt.image.IndexColorModel createMaskColorModel​(java.awt.Color color)
      Returns a 2-colour indexed colour model.
      java.awt.image.IndexColorModel getColorModel()
      Returns the colour model.
      int[] getPixels()
      Returns the pixel array.
      java.awt.Dimension getSize()
      Returns the dimensions of this image.
      void paintPixels​(java.awt.Graphics g, java.awt.Point origin)
      Paints this image to a given graphics context.
      void paintScaledPixels​(java.awt.Graphics g, java.awt.Point origin, int scale)
      Paints this image to a given graphics context, with each pixel scaled by an integer factor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PixelImage

        public PixelImage​(java.awt.Dimension size,
                          int[] pixels,
                          java.awt.image.IndexColorModel colorModel)
        Constructor.
        Parameters:
        size - dimensions of the image
        pixels - pixel array, fits size all values must fall in range of colour model
        colorModel - indexed colour model
    • Method Detail

      • getSize

        public java.awt.Dimension getSize()
        Returns the dimensions of this image.
        Returns:
        size
      • getPixels

        public int[] getPixels()
        Returns the pixel array.
        Returns:
        pixel array
      • getColorModel

        public java.awt.image.IndexColorModel getColorModel()
        Returns the colour model.
        Returns:
        colour model
      • paintPixels

        public void paintPixels​(java.awt.Graphics g,
                                java.awt.Point origin)
        Paints this image to a given graphics context.
        Parameters:
        g - graphics context
        origin - target position for origin of painted image
      • paintScaledPixels

        public void paintScaledPixels​(java.awt.Graphics g,
                                      java.awt.Point origin,
                                      int scale)
        Paints this image to a given graphics context, with each pixel scaled by an integer factor.
        Parameters:
        g - graphics context
        origin - target position for origin of painted image
        scale - scaling factor
      • createColorModel

        public static java.awt.image.IndexColorModel createColorModel​(Shader shader,
                                                                      boolean zeroTransparent)
        Returns an indexed colour model whose entries range from one end to the other of a given shader object.
        Parameters:
        shader - shader; should be absolute
        zeroTransparent - if true, the first entry in the returned colour map is transparent
        Returns:
        colour model
      • createMaskColorModel

        public static java.awt.image.IndexColorModel createMaskColorModel​(java.awt.Color color)
        Returns a 2-colour indexed colour model.
        Parameters:
        color - non-blank colour
        Returns:
        colour map with two entries: 0=transparent, 1=color