Class RasterImage


  • public class RasterImage
    extends java.lang.Object
    RasterImage is a Java class that generates a RenderedImage object from a Blob or a byte array.

    There are two constructors which take data in byte[] or Blob:
    public RasterImage( byte[] data, long height, long width, long nbands, String cellDepth, String interleaving) throws GeoRasterException;
    public RasterImage( Blob blob, long height, long width, long nbands, String cellDepth, String interleaving) throws GeoRasterException, SQLException;

    If nbands is 1 or 3 and nodataMapping has transparent=true this class will add an alpha band to apply nodataMapping transparent values.
    If setHasAlpha(true) is invoked and nbands is 2 or 4, the last band will be interpreted has alpha band.
    Example on how to use the class:
        
          //construct a RasterImage object using the data either in byte[] or Blob
          RasterImage ri = new RasterImage(data, 800, 600, 3, '8BIT_U', 'BIP');
    
          //optionally set the colormap, nodatamapping, or image processing.
          ri.setColormap(colormap);
          ri.setNodataMappings(nodataMapping);
          ri.setImageProcessing(GeoRasterImage.IP_EQUALIZATION);
          ri.setBandStatistcis("red", 0, 255, 80, 125, histogram);
    
          //get the RenderedImage object
          RenderedImage image = ri.getRenderedImage(false);
        
        
    • Constructor Detail

      • RasterImage

        public RasterImage​(byte[] data,
                           long height,
                           long width,
                           long nbands,
                           java.lang.String cellDepth,
                           java.lang.String interleaving)
                    throws GeoRasterException
        Constructs a RasterImage object with image information and image data in byte[].
        Parameters:
        data - The raw image data in a byte array.
        height - The height of the image.
        width - The width of the image.
        cellDepth - The cell depth of the image pixel, which is defined in RasterInfo class.
        interleaving - The interleaving of the image, which is defined in RasterInfo class.
        Throws:
        GeoRasterException
      • RasterImage

        public RasterImage​(java.sql.Blob blob,
                           long height,
                           long width,
                           long nbands,
                           java.lang.String cellDepth,
                           java.lang.String interleaving)
                    throws GeoRasterException,
                           java.sql.SQLException
        Constructs a RasterImage object with image information and image data in Blob.
        Parameters:
        blob - The image data.
        height - The height of the image.
        width - The width of the image.
        cellDepth - The cell depth of the image pixel, which is defined in RasterInfo class.
        interleaving - The interleaving of the image, which is defined in RasterInfo class.
        Throws:
        GeoRasterException
        java.sql.SQLException
    • Method Detail

      • setHasAlpha

        public void setHasAlpha​(boolean hasAlpha)
                         throws GeoRasterException
        Indicate if last band provided in the constructor of this class contains alpha data.
        Parameters:
        hasAlpha -
        Throws:
        GeoRasterException - if this object was not created with 2 or 4 nbands.
      • setColormap

        public void setColormap​(GeorColormap colormap)
        Set Colormap
        Parameters:
        colormap - The colormap to be associated the image
      • getColormap

        public GeorColormap getColormap()
        Get Colormap
        Returns:
        The current colormap associated with the image
      • setGrayscale

        public void setGrayscale​(GeorGrayscale grayscale)
        Set Grayscale
        Parameters:
        grayscale - The grayscale to be associated the image
      • getGrayScale

        public GeorGrayscale getGrayScale()
        Get Grayscale
        Returns:
        The current grayscale associated with the image
      • hasAlphaFromData

        public boolean hasAlphaFromData()
        Check if this image has alpha channel included in data provided in this class constructor.
        Returns:
        true or false
      • getNodataMappings

        public java.util.Vector<GeoRasterImage.NodataMapping> getNodataMappings()
        Get nodatamapping.
        Returns:
        NodataMapping objects in a vector
      • setImageProcessing

        public void setImageProcessing​(int method)
                                throws GeoRasterException
        Set the image processing operator.
        Parameters:
        method - The method of the image processing defined in GeoRasterImage class.
        Throws:
        GeoRasterException
      • setBandStatistics

        public void setBandStatistics​(java.lang.String bandName,
                                      double min,
                                      double max,
                                      double std,
                                      double mean,
                                      GeorHistogram histogram)
        Set band statistics for certain bands. The statistics is used by the image processing.
        Parameters:
        bandName - The name of the band, one of "red", "green" and "blue"
        min - The minimum value of the pixel in the band.
        max - The maximum value of the pixel in the band.
        std - The standard deviation value of the pixel in the band.
        mean - The mean value of the pixel in the band.
        histogram - The histogram of the band.
      • getRenderedImage

        public java.awt.image.RenderedImage getRenderedImage​(boolean isExport)
                                                      throws GeoRasterException,
                                                             java.io.IOException
        Create a RenderedImage object from the image.
        Returns:
        a RenderdImage
        Throws:
        GeoRasterException
        java.io.IOException
      • hasNodataTransparent

        public boolean hasNodataTransparent()