Class Image

java.lang.Object
com.luciad.drawing.Image
All Implemented Interfaces:
AutoCloseable

public final class Image extends Object implements AutoCloseable
An image with a width, height and pixel data in a specified pixel format.

The origin of an image (pixel (0, 0)) is defined at the top left corner, with the x axis pointing right, and the y axis pointing down.

  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • create

      @NotNull public static Image create(long width, long height, boolean isAlphaPreMultiplied, @NotNull PixelFormat pixelFormat, @NotNull ByteBuffer data)
      Creates an Image.
      Parameters:
      width - the width of the new image
      height - the height of the new image
      isAlphaPreMultiplied - true to indicate that the colors in the data buffer contain premultiplied alpha
      pixelFormat - the pixel format
      data - the pixel data. The buffer contains rows (left to right) of color data. The rows are ordered from top to bottom. The size of each color, and so also the size of the data buffer, is determined by the used PixelFormat.
      Returns:
      a new image
    • decode

      @NotNull public static Image decode(@NotNull ByteBuffer encodedImage) throws ParseException
      Decodes an encoded image.

      The buffer holds the bytes of an image file, not the raw pixel grid that create() takes. The format is detected from the content of the buffer. JPEG, PNG, TIFF, WebP and Radiance HDR images are supported.

      Parameters:
      encodedImage - the encoded image bytes
      Returns:
      the decoded image.
      Throws:
      ParseException - when the image format is not recognized or the image cannot be decoded.
      Since:
      2026.1
    • decode

      @NotNull public static Image decode(@NotNull String filePath) throws ParseException
      Decodes the encoded image stored in a file.

      The format is detected from the content of the file, not from its extension. JPEG, PNG, TIFF, WebP and Radiance HDR images are supported.

      Parameters:
      filePath - the path of a local image file. Remote locations such as http URLs are not supported.
      Returns:
      the decoded image.
      Throws:
      ParseException - when the file cannot be read, the image format is not recognized or the image cannot be decoded.
      Since:
      2026.1
    • getWidth

      public long getWidth()
      Returns the width of this image in pixels.
      Returns:
      the width of this image in pixels.
    • getHeight

      public long getHeight()
      Returns the height of this image in pixels.
      Returns:
      the height of this image in pixels.
    • getPixelFormat

      @NotNull public PixelFormat getPixelFormat()
      Returns the pixel format of this image.
      Returns:
      the pixel format of this image.
    • isAlphaPreMultiplied

      public boolean isAlphaPreMultiplied()
      Returns whether the image is using premultiplied alpha.
      Returns:
      true if the image is using premultiplied alpha.
    • getBytes

      @NotNull public ByteBuffer getBytes()
      Returns the bytes that make up the pixels of this image.

      The bytes must be immutable; multiple calls to this method must always result in the same bytes.
      The amount of bytes that makes up one pixel depends on the PixelFormat of this image (see getPixelFormat() and luciad::sizeInBytes(PixelFormat)). In other words, the size of this array is equal to: getWidth() * getHeight() * luciad::sizeInBytes(getPixelFormat()).
      The pixels are arranged in row-major order, starting in the upper-left corner.

      Returns:
      the bytes that make up the pixels of this image.
    • getColor

      @NotNull public android.graphics.Color getColor(long x, long y)
      Returns the color value at the given image location.

      This will be an rgba color for Image instance with:

      This will be a greyscale android.graphics.Color for Image instance with:

      Parameters:
      x - the x-coordinate of the pixel. A value of 0 corresponds with a left-most pixel.
      y - the y-coordinate of the pixel. A value of 0 corresponds with a top-most pixel.
      Returns:
      the android.graphics.Color value at the given image location.
    • fromBitmap

      @NotNull public static Image fromBitmap(@NotNull android.graphics.Bitmap bitmap)
      Creates an Image instance, based on the given bitmap
      Parameters:
      bitmap - a bitmap
      Returns:
      an Image instance
    • asBitmap

      @NotNull public android.graphics.Bitmap asBitmap()
      Converts an Image to a Bitmap.
      Returns:
      a new Bitmap instance based on this Image instance