public class ComponentImage

  1. Object
  2. Image
  3. ComponentImage

ImplementsActionSource

A utility wrapper that allows a Component to be used as an Image so that it can be set as the icon for a Label or button.

Nested types

class ComponentImage.EncodedWrapperA wrapper for ComponentImage to convert it to an EncodedImage.

Constructors

public ComponentImage(Component cmp, int w, int h)Creates a new image that renders the given component.

Methods

public Component getComponent()Gets the wrapped component that is rendered by this image.
public void enablePulsingAnimation(double currStep, double stepSize, double minAlpha, double maxAlpha)Enables a pulsing animation on the image.
public void disablePulsingAnimation()Disables the pulsing animation.
public boolean isPulsingAnimationEnabled()Checks if pulsing animation is enabled.
public int getWidth()Returns the width of the image
public int getHeight()Returns the height of the image
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 fill(int width, int height)Resizes/crops the image so that its center fills the given dimensions.
public Image applyMask(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.
public boolean isAnimation()Checks if this is an animation.
public void setAnimation(boolean anim)Sets whether this in an animation.
public boolean requiresDrawImage()Overridden to always return true so that the paint() method is called on this image.
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)Draws the image.
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 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 boolean animate()Advances this image’s animation state, if it is animated.
public EncodedImage toEncodedImage()Converts to an encoded image.

Inherited methods

Constructor details

ComponentImage

public ComponentImage(Component cmp, int w, int h)
Creates a new image that renders the given component.

Parameters

cmp Component
The component to render.
w int
The width of the image.
h int
The height of the image.

Method details

getComponent

public Component getComponent()
Gets the wrapped component that is rendered by this image.

enablePulsingAnimation

public void enablePulsingAnimation(double currStep, double stepSize, double minAlpha, double maxAlpha)
Enables a pulsing animation on the image.

Parameters

currStep double
The current step.
stepSize double
The step size.
minAlpha double
The min alpha
maxAlpha double
The max alpha

disablePulsingAnimation

public void disablePulsingAnimation()
Disables the pulsing animation.

isPulsingAnimationEnabled

public boolean isPulsingAnimationEnabled()
Checks if pulsing animation is enabled.

getWidth

public int getWidth()
Returns the width of the image

Returns

the width of the image

getHeight

public int getHeight()
Returns the height of the image

Returns

the height of the 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

fill

public Image fill(int width, int height)
Resizes/crops the image so that its center fills the given dimensions. This is similar to com.codename1.ui.plaf.Style#BACKGROUND_IMAGE_SCALED_FILL

Parameters

width int
the width to fill
height int
the height to fill

Returns

a new image (or the same image if dimensions happen to match) filling the width/height

applyMask

public Image applyMask(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.

Returns

image masked based on the given object

Throws

IllegalArgumentException
if the image size doesn’t match the mask size

isAnimation

public boolean isAnimation()
Checks if this is an animation.

Returns

true if this image represents an animation

setAnimation

public void setAnimation(boolean anim)
Sets whether this in an animation.

Parameters

anim boolean
True to make this an animated image

requiresDrawImage

public boolean requiresDrawImage()
Overridden to always return true so that the paint() method is called on this image.

Returns

true if a drawImage call is a required

drawImage

protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)
Draws the image.

Parameters

g Graphics
The graphics context
nativeGraphics Object
The native graphics context
x int
The x coordinate at which to draw the image.
y int
The y coordinate at which to draw the image.

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.

Parameters

g Graphics
the graphics object
nativeGraphics Object
the underlying native graphics which might be essential for some image types
x int
the x coordinate
y int
the y coordinate
w int
the width to occupy
h int
the height to occupy

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 int
width for the scaling
height int
height of the scaled image

Returns

new image instance scaled to the given height and width

animate

public boolean animate()
Advances this image’s animation state, if it is animated.

Returns

true if the animation state changed.

toEncodedImage

public EncodedImage toEncodedImage()
Converts to an encoded image.