public class RGBImage
ImplementsActionSource
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
Constructors
public RGBImage(Image img) | Converts an image to an RGB image after which the original image can be GC’d |
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 |
Methods
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. |
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. |
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 |
public Image rotate(int degrees) | Unsupported in the current version, this method will be implemented in a future release |
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. |
public Graphics getGraphics() | This method is unsupported in this image type |
public int[] getRGB() | Returns a mutable array that can be used to change the appearance of the image arranged as AARRGGBB. |
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. |
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, int w, int h) | Callback invoked internally by Codename One to draw the image/frame onto the display. |
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. |
public void setOpaque(boolean opaque) | Sets whether this image should be treated as fully opaque. |
public int getWidth() | Returns the width of the image |
public int getHeight() | Returns the height of the image |
public boolean requiresDrawImage() | New label optimizations don’t invoke drawImage and instead just pass the native image directly to the underlying renderer. |
Inherited methods
From Image
isSimdOptimizationsEnabled, setSimdOptimizationsEnabled, resetSimdOptimizationsEnabled, isSVGSupported, createSVG, createIndexed, createImage, createImage, createImage, createImage, createImage, isAlphaMutableImageSupported, createImage, createImage, exifRotation, exifRotation, exifRotation, getExifOrientationTag, getExifOrientationTag, isJPEG, isPNG, asyncLock, lock, isLocked, unlock, getSVGDocument, isSVG, createMask, applyMask, applyMask, applyMaskAutoScale, mirror, modifyAlphaWithTranslucency, modifyAlpha, toRGB, getRGB, getRGBCached, scaledWidth, scaledHeight, scaledSmallerRatio, scaledLargerRatio, fill, getImage, isAnimation, animate, getImageName, setImageName, dispose, rotate90Degrees, rotate180Degrees, rotate270Degrees, flipHorizontally, flipVertically, addActionListener, removeActionListener, fireChangedEvent
Constructor details
RGBImage
public RGBImage(Image img)Parameters
imgImage- the image to convert to an RGB image
RGBImage
public RGBImage(int[] rgb, int width, int height)Parameters
rgbint[]- AARRGGBB array
widthint- width of image
heightint- height of image
Method details
subImage
public Image subImage(int x, int y, int width, int height, boolean processAlpha)Parameters
xint- the x offset from the image
yint- the y offset from the image
widthint- the width of internal images
heightint- the height of internal images
processAlphaboolean- whether alpha should be processed as well as part of the cutting
Returns
scaled
public Image scaled(int width, int height)Parameters
widthint- width for the scaling
heightint- height of the scaled image
Returns
scale
public void scale(int width, int height)Parameters
widthint- width for the scaling
heightint- height of the scaled image
rotate
public Image rotate(int degrees)Parameters
degreesint- A degree in right angle must be larger than 0 and up to 359 degrees
Returns
modifyAlpha
public Image modifyAlpha(byte alpha)Parameters
alphabyte- New value for the entire alpha channel
Returns
getGraphics
public Graphics getGraphics()Returns
getRGB
public int[] getRGB()Returns
drawImage
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)Parameters
gGraphics- the graphics object
nativeGraphicsObject- the underlying native graphics which might be essential for some image types
xint- the x coordinate
yint- the y coordinate
drawImage
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, int w, int h)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.
RGBImage has no native peer, so the inherited scaled-draw path
(g.drawImageWH(image, ...)) renders nothing. Instead, build a
translate + scale affine transform on top of the graphics context’s
current transform and emit drawRGB at the image’s native size –
the platform pipeline (iOS Metal, Android Skia, Graphics2D, …)
performs the actual scaling in hardware / native code.
Graphics.setTransform is used (rather than translateMatrix +
scale) because on ports where impl.isTranslationSupported() is
false (iOS), prior g.translate(int, int) calls accumulate into a
per-Graphics integer translate that is baked into draw coordinates
before the impl matrix is applied. A naked translateMatrix /
scale composition would therefore multiply that accumulator by
the scale factor, shifting the on-screen position. setTransform
conjugates the matrix with T(xTranslate, yTranslate), cancelling
the accumulator so the result lands at the requested coordinates
on every port.
Parameters
gGraphics- the graphics object
nativeGraphicsObject- the underlying native graphics which might be essential for some image types
xint- the x coordinate
yint- the y coordinate
wint- the width to occupy
hint- the height to occupy
isOpaque
public boolean isOpaque()Returns
setOpaque
public void setOpaque(boolean opaque)Parameters
opaquebooleantrueto treat this image as opaque.
getWidth
public int getWidth()Returns
getHeight
public int getHeight()Returns
requiresDrawImage
public boolean requiresDrawImage()