Class RGBImage
- All Implemented Interfaces:
ActionSource
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCallback invoked internally by Codename One to draw the image/frame onto the display.This method is unsupported in this image typeintReturns the height of the imageint[]getRGB()Returns a mutable array that can be used to change the appearance of the image arranged as AARRGGBB.intgetWidth()Returns the width of the imagebooleanisOpaque()Indicates if an image should be treated as opaque, this can improve support for fast drawing of RGB images without alpha support.modifyAlpha(byte alpha) Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.booleanNew label optimizations don't invoke drawImage and instead just pass the native image directly to the underlying renderer.rotate(int degrees) Unsupported in the current version, this method will be implemented in a future releasevoidscale(int width, int height) Scale the image to the given width and height, this is a fast algorithm that preserves translucent informationscaled(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.voidsetOpaque(boolean opaque) 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.Methods inherited from class Image
addActionListener, animate, applyMask, applyMask, applyMaskAutoScale, asyncLock, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, dispose, drawImage, exifRotation, exifRotation, exifRotation, fill, fireChangedEvent, flipHorizontally, flipVertically, getExifOrientationTag, getExifOrientationTag, getImage, getImageName, getRGB, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isAnimation, isJPEG, isLocked, isPNG, isSVG, isSVGSupported, lock, mirror, modifyAlpha, modifyAlphaWithTranslucency, removeActionListener, rotate180Degrees, rotate270Degrees, rotate90Degrees, scaledHeight, scaledLargerRatio, scaledSmallerRatio, scaledWidth, setImageName, toRGB, unlock
-
Constructor Details
-
RGBImage
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
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
-
-
scaled
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
-
-
scale
-
rotate
-
modifyAlpha
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:
modifyAlphain classImage- Returns:
- Translucent/Opaque image based on the alpha value and the pixels of this image
-
getGraphics
This method is unsupported in this image type- Overrides:
getGraphicsin classImage
-
getRGB
-
drawImage
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
-
-
isOpaque
-
setOpaque
public void setOpaque(boolean opaque) -
getWidth
-
getHeight
-
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:
requiresDrawImagein classImage
-