Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Raster

  1. Object
  2. Raster

A rectangle of non-premultiplied 0xAARRGGBB pixels with a position.

The renderer paints every layer into a Raster and composites them with Compositor, so a document looks the same on every port and in tests that have no display.

Fields

public static final int MAX_PIXELS = 67108864The largest number of pixels a raster may hold: 64 megapixels.

Constructors

public Raster(int x, int y, int width, int height)Creates a transparent raster.
public Raster(int x, int y, int width, int height, int[] pixels)Wraps existing pixels.

Methods

public int getX()Left edge.
public int getY()Top edge.
public int getWidth()Width in pixels.
public int getHeight()Height in pixels.
public int[] getPixels()The pixel array, row major.
public int get(int px, int py)The pixel at absolute coordinates, transparent outside.
public Raster copy()A deep copy.
public boolean isEmpty()True when every pixel is fully transparent.
public Raster resize(int nx, int ny, int nw, int nh)Returns a raster covering [nx, ny, nw, nh] with this one’s pixels copied in.
public void composite(Raster src, BlendMode mode, float opacity)Composites src onto this raster where they overlap.
public void applyMask(byte[] mask)Multiplies each pixel’s alpha by a coverage mask of the same geometry (0..255).
public Raster transform(Matrix m, int[] clip)Returns this raster drawn through a transform, sampled bilinearly, clipped to the device rectangle clip (x, y, w, h) when it is not null.

Inherited methods

Field details

MAX_PIXELS

public static final int MAX_PIXELS = 67108864
The largest number of pixels a raster may hold: 64 megapixels.

Constructor details

Raster

public Raster(int x, int y, int width, int height)
Creates a transparent raster.

Parameters

x int
left edge in device pixels
y int
top edge in device pixels
width int
width, at least 0
height int
height, at least 0

Raster

public Raster(int x, int y, int width, int height, int[] pixels)
Wraps existing pixels.

Parameters

x int
left edge
y int
top edge
width int
width
height int
height
pixels int[]
width * height pixels, row major; null for transparent

Method details

getX

public int getX()
Left edge.

getY

public int getY()
Top edge.

getWidth

public int getWidth()
Width in pixels.

getHeight

public int getHeight()
Height in pixels.

getPixels

public int[] getPixels()
The pixel array, row major. Changes write through.

get

public int get(int px, int py)
The pixel at absolute coordinates, transparent outside.

Parameters

px int
absolute x
py int
absolute y

copy

public Raster copy()
A deep copy.

isEmpty

public boolean isEmpty()
True when every pixel is fully transparent.

resize

public Raster resize(int nx, int ny, int nw, int nh)
Returns a raster covering [nx, ny, nw, nh] with this one’s pixels copied in.

Parameters

nx int
new left edge
ny int
new top edge
nw int
new width
nh int
new height

composite

public void composite(Raster src, BlendMode mode, float opacity)
Composites src onto this raster where they overlap.

Parameters

src Raster
the layer
mode BlendMode
how colors combine
opacity float
the layer’s opacity, 0 to 1

applyMask

public void applyMask(byte[] mask)
Multiplies each pixel’s alpha by a coverage mask of the same geometry (0..255).

Parameters

mask byte[]
one byte of coverage per pixel

transform

public Raster transform(Matrix m, int[] clip)
Returns this raster drawn through a transform, sampled bilinearly, clipped to the device rectangle clip (x, y, w, h) when it is not null.

Parameters

m Matrix
maps this raster’s absolute coordinates to device coordinates
clip int[]
limits the result; may be null