Class ReplaceableImage
java.lang.Object
com.codename1.ui.Image
com.codename1.ui.EncodedImage
com.codename1.components.ReplaceableImage
- All Implemented Interfaces:
ActionSource
Allows the image data to be replaced at runtime when a different image is
available. The only limitation is that the image width/height must be identical and
opacity status can't change (an opaque image can't be made translucent and visa versa).
-
Method Summary
Modifier and TypeMethodDescriptionbooleananimate()Advances this image's animation state, if it is animated.static ReplaceableImagecreate(EncodedImage placeholder) Creates an encoded image that can later be replaced with a different imagebyte[]Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.booleanReturns true if this is an animated imagebooleanisOpaque()Indicates whether this image is opaque or notvoidreplace(EncodedImage newImage) Replaces the current image with the new image which must match the dimensions etc.Methods inherited from class EncodedImage
asyncLock, create, create, create, create, create, createFromImage, createFromRGB, createMulti, drawImage, drawImage, getGraphics, getHeight, getImage, getInternal, getWidth, isLocked, lock, modifyAlpha, modifyAlpha, resetCache, rotate, scale, scaled, scaledEncoded, scaledHeight, scaledSmallerRatio, scaledWidth, subImage, toRGB, unlockModifier and TypeMethodDescriptionvoidAsync 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 EncodedImagecreate(byte[] data) Creates an image from the given byte arraystatic EncodedImagecreate(byte[] data, int width, int height, boolean opacity) Creates an image from the given byte array with the variables set appropriately.static EncodedImageCreates an image from the input streamstatic EncodedImagecreate(InputStream i, int size) Creates an image from the input stream, this version of the method is somewhat faster than the version that doesn't accept sizestatic EncodedImageCreates an image from the input streamstatic EncodedImagecreateFromImage(Image i, boolean jpeg) Converts an image to encoded imagestatic ImagecreateFromRGB(int[] argb, int width, int height, boolean jpeg) Tries to create an encoded image from RGB which is more efficient, however if this fails it falls back to regular RGB image.static EncodedImagecreateMulti(int[] dpis, byte[][] data) Creates an encoded image that acts as a multi-image, DO NOT USE THIS METHOD.protected voidCallback invoked internally by Codename One to draw the image/frame onto the display.protected voidCallback invoked internally by Codename One to draw the image/frame onto the display.If this is a mutable image a graphics object allowing us to draw on it is returned.intReturns the height of the imagegetImage()Returns the platform specific image implementation, warning the implementation class can change between revisions of Codename One and platforms.protected ImageReturns the actual image represented by the encoded image, this image will be cached in a weak/soft reference internally.intgetWidth()Returns the width of the imagebooleanisLocked()Returns true if the image is lockedvoidlock()This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g.modifyAlpha(byte alpha) Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.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.protected voidA subclass might choose to load asynchroniously and reset the cache when the image is ready.rotate(int degrees) Returns an instance of this image rotated by the given number of degrees.voidscale(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.scaledEncoded(int width, int height) Performs scaling using ImageIO to generate an encoded ImagescaledHeight(int height) Scales the image to the given height while updating the width based on the aspect ratio of the heightscaledSmallerRatio(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 widthsubImage(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.voidExtracts 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 Image
addActionListener, applyMask, applyMask, applyMaskAutoScale, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, dispose, exifRotation, exifRotation, exifRotation, fill, fireChangedEvent, flipHorizontally, flipVertically, getExifOrientationTag, getExifOrientationTag, getImageName, getRGB, getRGB, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isJPEG, isPNG, isSVG, isSVGSupported, mirror, modifyAlphaWithTranslucency, removeActionListener, requiresDrawImage, rotate180Degrees, rotate270Degrees, rotate90Degrees, scaledLargerRatio, setImageNameModifier and TypeMethodDescriptionvoidAdds ActionListener to receive action events form this source.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.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.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.The name of the image is set for some images mostly to ease the debugging of Codename One applicationint[]getRGB()Returns the content of this image as a newly created ARGB array.voidgetRGB(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 transparencystatic booleanisJPEG(InputStream inputStream) Very fast method to detect if the given inputStream is a JPEG image (according to its guessed mime type)static 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 Imagemirror()Creates a mirror image for the given image which is useful for some RTL scenarios.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.booleanNew label optimizations don't invoke drawImage and instead just pass the native image directly to the underlying renderer.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 picturescaledLargerRatio(int width, int height) Scales the image while maintaining the aspect ratio to the larger size imagevoidsetImageName(String imageName) The name of the image is set for some images mostly to ease the debugging of Codename One applicationMethods 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.
-
Method Details
-
create
Creates an encoded image that can later be replaced with a different image
Parameters
placeholder: a temporary image
Returns
image that will be replaceable later on
-
getImageData
public byte[] getImageData()Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.
Returns
byte array used to create the image, e.g. encoded PNG, JPEG etc.
- Overrides:
getImageDatain classEncodedImage
-
replace
Replaces the current image with the new image which must match the dimensions etc. of the previous image.
Parameters
newImage: the image to apply
-
animate
-
isAnimation
public boolean isAnimation()Returns true if this is an animated image
Returns
true if this image represents an animation
- Overrides:
isAnimationin classEncodedImage
-
isOpaque
public boolean isOpaque()Indicates whether this image is opaque or not
Returns
true if the image is completely opqaque which allows for some heavy optimizations
- Overrides:
isOpaquein classEncodedImage
-