Class ImageRenderer

  • public class ImageRenderer
    extends Object
    A builder for the rendered image to be returned by Grid­Coverage​.render(Grid­Extent). This builder does not copy any sample values. Instead, it wraps existing data arrays into Raster objects by computing required information such as pixel stride, scanline stride and band offsets. Different set­Data(…) methods are provided for allowing to specify the data arrays from different objects such as Java2D Data­Buffer or NIO Buffer.

    All set­Data(…) methods assume that the first valid element in each array is the value located at Grid­Coverage​.get­Grid­Geometry().get­Extent().get­Low(). This Image­Renderer class computes automatically the offsets from that position to the position of the first value included in the slice­Extent given to the constructor.

    Usage example:
    class MyResource extends GridCoverage {
        public RenderedImage render(GridExtent sliceExtent) {
            try {
                ImageRenderer renderer = new ImageRenderer(this, sliceExtent);
                return renderer.image();
            } catch (IllegalArgumentException | ArithmeticException | RasterFormatException e) {
                throw new CannotEvaluateException("Can not create an image.", e);
    Current implementation constructs only images made of a single tile. Support for tiled images will be added in a future version.
    See Also:

    Defined in the sis-feature module

    • Constructor Detail

      • ImageRenderer

        public ImageRenderer​(GridCoverage coverage,
                             GridExtent sliceExtent)
        Creates a new image renderer for the given slice extent.
        coverage - the grid coverage for which to build an image.
        slice­Extent - the grid geometry from which to create an image, or null for the coverage extent.
        Subspace­Not­Specified­Exception - if this method can not infer a two-dimensional slice from slice­Extent.
        Disjoint­Extent­Exception - if the given extent does not intersect this grid coverage.
        Arithmetic­Exception - if a stride calculation overflows the 32 bits integer capacity.
    • Method Detail

      • getNumBands

        public final int getNumBands()
        Returns the number of bands that the image will have. By default, this is the number of sample dimensions in the grid coverage.
        the number of bands in the rendered image.
      • getBounds

        public final Rectangle getBounds()
        Returns the location of the image upper-left corner together with the image size.
        the rendered image location and size (never null).
      • setInterleavedPixelOffsets

        public void setInterleavedPixelOffsets​(int pixelStride,
                                               int[] bandOffsets)
        Specifies the offsets to add to sample index in each band in order to reach the sample value in the Data­Buffer bank. This method should be invoked when the data given to set­Data(…) contains only one Vector, Buffer or Data­Buffer bank, and the bands in that unique bank are interleaved.
        Example: for an image having three bands named Red (R), Green (G) and Blue (B), if the sample values are stored in a single bank in a R₀,G₀,B₀, R₁,G₁,B₁, R₂,G₂,B₂, R₃,G₃,B₃, etc. fashion, then this method should be invoked as below:
        setInterleavedPixelOffsets(3, new int[] {0, 1, 2});
        pixel­Stride - the number of data elements between each pixel in the data vector or buffer.
        band­Offsets - offsets to add to sample index in each band. This is typically {0, 1, 2, …}. The length of this array shall be equal to get­Num­Bands().