public abstract class DynamicImage

  1. Object
  2. Image
  3. DynamicImage

ImplementsActionSource

A base class for images that dynamically painted, just like a normal component. Subclasses just need to implement the java.lang.Object, int, int, int, int) method.

Constructors

public DynamicImage()Constructor.
public DynamicImage(int w, int h)Constructor with width and height.

Methods

public static void setIcon(Label lbl, DynamicImage img)Sets the given image as the icon for the specified label.
public Style getStyle()Gets the style for this image.
public void setStyle(Style s)Sets the style to be used for drawing the image.
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 requiresDrawImage()New label optimizations don’t invoke drawImage and instead just pass the native image directly to the underlying renderer.
protected abstract void drawImageImpl(Graphics g, Object nativeGraphics, int x, int y, int w, int h)This method should be overridden by subclasses to perform the actual drawing of the image on a graphics context.
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.

Inherited methods

Constructor details

DynamicImage

public DynamicImage()
Constructor. Creates image of default size: 250x250 pixels.

DynamicImage

public DynamicImage(int w, int h)
Constructor with width and height.

Parameters

w int
The width of the image.
h int
The height of the image.

Method details

setIcon

public static void setIcon(Label lbl, DynamicImage img)
Sets the given image as the icon for the specified label. This will link the label’s style with the image just before each call the java.lang.Object, int, int, int, int) so that the image can correctly adapt to the label’s style.

getStyle

public Style getStyle()
Gets the style for this image.

setStyle

public void setStyle(Style s)
Sets the style to be used for drawing the image. The java.lang.Object, int, int, int, int) can use any aspect of this style to customize the drawing.

Parameters

s Style
The style.

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

Parameters

width int
width for the scaling
height int
height of the scaled image

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.

Parameters

mask Object
mask object created by the createMask() method.

Returns

image masked based on the given object

Throws

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

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

drawImageImpl

protected abstract void drawImageImpl(Graphics g, Object nativeGraphics, int x, int y, int w, int h)
This method should be overridden by subclasses to perform the actual drawing of the image on a graphics context.

Parameters

g Graphics
The graphics context
nativeGraphics Object
THe native graphics context.
x int
x-coordinate of the bounds to draw.
y int
y-coordinate of the bounds to draw.
w int
width of the bounds
h int
height of the bounds

drawImage

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. 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

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