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) Sets whether this image should be treated as fully 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, unlockModifier and TypeMethodDescriptionvoidAdds ActionListener to receive action events form this source.booleananimate()Advances this image's animation state, if it is animated.Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.applyMaskAutoScale(Object mask) Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.voidAsync lock is the equivalent of a lock operation, however it uses the given image as the hard cache and performs the actual image loading asynchronously.static ImagecreateImage(byte[] bytes, int offset, int len) creates an image from a given byte array datastatic ImagecreateImage(int[] rgb, int width, int height) creates an image from an RGB imagestatic ImagecreateImage(int width, int height) Creates a white opaque mutable image that may be manipulated using#getGraphics().static ImagecreateImage(int width, int height, int fillColor) Creates a mutable image that may be manipulated using#getGraphics().static ImagecreateImage(InputStream stream) creates an image from an InputStreamstatic ImagecreateImage(Object nativeImage) creates an image from the given native image (e.g. MIDP image object)static ImagecreateImage(String path) Creates an image from a path.static ImagecreateIndexed(int width, int height, int[] palette, byte[] data) Creates an indexed image with byte data this method may return a native indexed image rather than an instance of the IndexedImage classCreates a mask from the given image, a mask can be used to apply an arbitrary alpha channel to any image.static ImageCreates an SVG Image from the given byte array data and the base URL, this method will throw an exception if SVG is unsupported.voiddispose()DO NOT CALL THIS METHOD UNLESS YOU KNOW WHAT YOU ARE DOING, IT WILL CAUSE PLATFORM SPECIFC CRASHES OTHERWISE! Images dispose automatically for most cases except for very rare special cases.protected voidCallback invoked internally by Codename One to draw the image/frame onto the display.static ImageexifRotation(String capturedImage) The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.static ImageexifRotation(String capturedImage, String rotatedImage) The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.static ImageexifRotation(String capturedImage, String rotatedImage, int maxSize) The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.fill(int width, int height) Resizes/crops the image so that its center fills the given dimensions.voidflipHorizontally(boolean maintainOpacity) Flips this image on the horizontal axisflipVertically(boolean maintainOpacity) Flips this image on the vertical axisstatic intGets the EXIF orientation tag of an image, if it's available.static intgetExifOrientationTag(String path) Gets the EXIF orientation tag of an image if it's available.getImage()Returns the platform specific image implementation, warning the implementation class can change between revisions of Codename One and platforms.The name of the image is set for some images mostly to ease the debugging of Codename One applicationvoidgetRGB(int[] rgbData) Returns the content of this image in the supplied ARGB array.int[]Returns the content of this image as a newly created ARGB array or a cached instance if possible.Returns a platform specific DOM object that can be manipulated by the user to change the SVG Imagestatic booleanReturns true if mutable images support alpha transparencybooleanReturns true if this is an animated imagestatic booleanisJPEG(InputStream inputStream) Very fast method to detect if the given inputStream is a JPEG image (according to its guessed mime type)booleanisLocked()Returns true if the image is lockedstatic booleanisPNG(InputStream inputStream) Very fast method to detect if the given inputStream is a PNG image (according to its guessed mime type)booleanisSVG()Indicates if this image represents an SVG file or a bitmap filestatic booleanIndicates whether the underlying platform supports creating an SVG Imagevoidlock()This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g.mirror()Creates a mirror image for the given image which is useful for some RTL scenarios.modifyAlpha(byte alpha, int removeColor) Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.modifyAlphaWithTranslucency(byte alpha) Creates a new image instance with the alpha channel of opaque pixels within the image using the new alpha value.voidRemoves ActionListener so that it will no longer receive events from this source.rotate180Degrees(boolean maintainOpacity) Rotates the image by 180 degreesrotate270Degrees(boolean maintainOpacity) Rotates the image by 270 degrees while changing the ratio of the picturerotate90Degrees(boolean maintainOpacity) Rotates this image by 90 degrees while changing the ratio of the picturescaledHeight(int height) Scales the image to the given height while updating the width based on the aspect ratio of the heightscaledLargerRatio(int width, int height) Scales the image while maintaining the aspect ratio to the larger size imagescaledSmallerRatio(int width, int height) Scales the image while maintaining the aspect ratio to the smaller size imagescaledWidth(int width) Scales the image to the given width while updating the height based on the aspect ratio of the widthvoidsetImageName(String imageName) The name of the image is set for some images mostly to ease the debugging of Codename One applicationvoidExtracts data from this image into the given RGBImagevoidunlock()This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()booleanIndicates whether some other object is "equal to" this one.final ClassgetClass()Returns the runtime class of an object.inthashCode()Returns a hash code value for the object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
-
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) Sets whether this image should be treated as fully opaque.
Parameters
opaque:trueto treat this image as 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
-