Class RGBImage

java.lang.Object
com.codename1.ui.Image
com.codename1.ui.RGBImage
All Implemented Interfaces:
ActionSource

public class RGBImage extends Image

An image that stores its data as an integer RGB array internally, this image cannot be manipulated via Graphics primitives however its array is accessible and modifiable programmatically. This is very useful for 2 distinct use cases.

The first use case allows us to manipulate images in a custom way while still preserving alpha information where applicable.

The second use case allows us to store images in the Java heap which is useful for some constrained devices. In small devices images are often stored in a separate "heap" which runs out eventually, this allows us to place the image in the Java heap which is potentially more wasteful but might sometimes be more abundant.

Note that unless specified otherwise most methods inherited from Image will fail when invoked on this subclass often with a NullPointerException. This image can be drawn on graphics as usual

  • Constructor Details

    • RGBImage

      public RGBImage(Image img)

      Converts an image to an RGB image after which the original image can be GC'd

      Parameters
      • img: the image to convert to an RGB image
    • RGBImage

      public RGBImage(int[] rgb, int width, int height)

      Creates an RGB image from scratch the array isn't copied and can be saved and manipulated

      Parameters
      • rgb: AARRGGBB array

      • width: width of image

      • height: height of image

  • Method Details

    • subImage

      public Image subImage(int x, int y, int width, int height, boolean processAlpha)

      Extracts a subimage from the given image allowing us to breakdown a single large image into multiple smaller images in RAM, this actually creates a standalone version of the image for use.

      Parameters
      • x: the x offset from the image

      • y: the y offset from the image

      • width: the width of internal images

      • height: the height of internal images

      • processAlpha: whether alpha should be processed as well as part of the cutting

      Returns

      An array of all the possible images that can be created from the source

      Overrides:
      subImage in class Image
    • scaled

      public Image scaled(int width, int height)

      Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information. The method accepts -1 to preserve aspect ratio in the given axis.

      Parameters
      • width: width for the scaling

      • height: height of the scaled image

      Returns

      new image instance scaled to the given height and width

      Overrides:
      scaled in class Image
    • scale

      public void scale(int width, int height)

      Scale the image to the given width and height, this is a fast algorithm that preserves translucent information

      Parameters
      • width: width for the scaling

      • height: height of the scaled image

      Deprecated
      Overrides:
      scale in class Image
    • rotate

      public Image rotate(int degrees)
      Unsupported in the current version, this method will be implemented in a future release
      Overrides:
      rotate in class Image
    • modifyAlpha

      public Image modifyAlpha(byte alpha)

      Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value. Transparent (alpha == 0) pixels remain transparent. All other pixels will have the new alpha value.

      Parameters
      • alpha: New value for the entire alpha channel
      Returns
      Overrides:
      modifyAlpha in class Image
      Returns:
      Translucent/Opaque image based on the alpha value and the pixels of this image
    • getGraphics

      public Graphics getGraphics()
      This method is unsupported in this image type
      Overrides:
      getGraphics in class Image
    • getRGB

      public int[] getRGB()

      Returns a mutable array that can be used to change the appearance of the image arranged as AARRGGBB.

      Returns

      ARGB int array

      Overrides:
      getRGB in class Image
    • drawImage

      protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)

      Callback invoked internally by Codename One to draw the image/frame onto the display. Image subclasses can override this method to perform drawing of custom image types.

      Parameters
      • g: the graphics object

      • nativeGraphics: the underlying native graphics which might be essential for some image types

      • x: the x coordinate

      • y: the y coordinate

      Overrides:
      drawImage in class Image
    • isOpaque

      public boolean isOpaque()
      Indicates if an image should be treated as opaque, this can improve support for fast drawing of RGB images without alpha support.
      Overrides:
      isOpaque in class Image
    • setOpaque

      public void setOpaque(boolean opaque)
    • getWidth

      public int getWidth()

      Returns the width of the image

      Returns

      the width of the image

      Overrides:
      getWidth in class Image
    • getHeight

      public int getHeight()

      Returns the height of the image

      Returns

      the height of the image

      Overrides:
      getHeight in class Image
    • requiresDrawImage

      public boolean requiresDrawImage()

      New label optimizations don't invoke drawImage and instead just pass the native image directly to the underlying renderer. This is problematic for some image types specifically timeline & FontImage and this method allows these classes to indicate that they need that legacy behavior of calling drawImage.

      Returns

      true if a drawImage call is a required

      Overrides:
      requiresDrawImage in class Image