Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class RasterImage
- Object
- RasterImage
A mutable image held in memory as 32-bit ARGB pixels.
Pixels are not premultiplied: 0x80FF0000 is half transparent pure
red. They are stored row by row with no padding, so pixel (x, y) is
getPixels()[y * getWidth() + x].
Unlike com.codename1.ui.Image this class needs no display and no
platform: it runs on a device, in the simulator and on a Codename One
server alike. Draw into it with RasterGraphics, read and write files with
PngCodec and JpegCodec, and hand the pixels to the UI with
Image.createImage(raster.getPixels(), w, h) when you need one.
Constructors
public RasterImage(int width, int height) | Creates a fully transparent image. |
public RasterImage(int width, int height, int[] argb) | Wraps an existing ARGB array without copying it. |
Methods
Inherited methods
Constructor details
RasterImage
public RasterImage(int width, int height)Parameters
widthint- width in pixels, at least 1
heightint- height in pixels, at least 1
RasterImage
public RasterImage(int width, int height, int[] argb)Parameters
widthint- width in pixels
heightint- height in pixels
argbint[]- at least
width * heightnon-premultiplied ARGB pixels
Method details
getWidth
public int getWidth()getHeight
public int getHeight()getPixels
public int[] getPixels()getRGB
public int getRGB(int x, int y)(x, y).Parameters
xint- column
yint- row
Returns
ArrayIndexOutOfBoundsException or
IllegalArgumentException for a point outside the imagesetRGB
public void setRGB(int x, int y, int argb)(x, y), replacing what was there.Parameters
xint- column
yint- row
argbint- the new pixel
fill
public void fill(int argb)Parameters
argbint- the pixel value
copy
public RasterImage copy()subImage
public RasterImage subImage(int x, int y, int w, int h)Parameters
xint- left edge
yint- top edge
wint- width
hint- height; the rectangle must lie inside the image
Returns
scale
public RasterImage scale(int w, int h, int filter)Returns this image resized with one of the Resampler filters.
Color is filtered premultiplied, so transparent pixels do not darken
the edges of what is next to them. The convolution filters give the
same bytes as Pillow’s resize.
Parameters
wint- new width
hint- new height
filterintResampler.NEAREST,BILINEAR,BICUBIC,LANCZOS,BOXorHAMMING
Returns
toRGBA
public byte[] toRGBA()R, G, B, A bytes, row by row.fromRGBA
public static RasterImage fromRGBA(int w, int h, byte[] rgba)R, G, B, A bytes, row by row.Parameters
wint- width
hint- height
rgbabyte[]w * h * 4bytes, not premultiplied
Returns
rotate90
public RasterImage rotate90()rotate180
public RasterImage rotate180()rotate270
public RasterImage rotate270()flipHorizontal
public RasterImage flipHorizontal()flipVertical
public RasterImage flipVertical()createGraphics
public RasterGraphics createGraphics()RasterGraphics that draws into this image.