Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
package com.codename1.backend.image
Server-side images: pixels, drawing, resampling and PNG/JPEG codecs in
pure Java, for a Codename One backend that has no display – social cards,
thumbnails, badges and charts rendered on the server. A client application
uses com.codename1.ui.Image and com.codename1.ui.Graphics instead.
RasterImageholds non-premultiplied ARGB pixels and rotates, flips, crops and resizes them.RasterGraphicsdraws antialiased lines, rectangles, ellipses, arcs, polygons and Bezier paths (RasterPath), with transforms, clipping, alpha, gradients (RasterGradient) and images. Text goes through theRasterFontseam;TrueTypeFontreads TrueType fonts and embeds a default one, so text needs no font file.Resampleris Pillow’s resampling convolution, byte for byte.PngCodecandJpegCodecread and write files.
A server builds a social card like this:
RasterImage card = new RasterImage(1200, 630);
RasterGraphics g = card.createGraphics();
g.setPaint(RasterGradient.linear(0, 0, 0, 630,
new float[] {0, 1}, new int[] {0xff1e3a8a, 0xff0ea5e9}));
g.fillRect(0, 0, 1200, 630);
g.setPaint(null);
g.setColor(0xccffffff);
g.fillRoundRect(60, 60, 1080, 510, 48, 48);
byte[] png = PngCodec.encode(card);Every class depends on nothing but the subset of the JDK the backend runtime provides, so it runs on the JVM and translated by ParparVM alike.
Types
class JpegCodec | Reads and writes JPEG files in pure Java. |
class PngCodec | Reads and writes PNG files in pure Java. |
interface RasterFont | The seam through which RasterGraphics.drawString(String, double, double) draws text: a font turns a string into an outline, and the graphics fills it like any other path. |
class RasterGradient | A linear or radial color gradient for RasterGraphics.setPaint(RasterPaint). |
class RasterGraphics | Draws antialiased shapes, gradients and images into a RasterImage. |
class RasterImage | A mutable image held in memory as 32-bit ARGB pixels. |
interface RasterPaint | What RasterGraphics fills with when it is not a single color: a gradient (RasterGradient) or your own pattern. |
class RasterPath | A shape made of straight lines and quadratic and cubic Bezier curves, for RasterGraphics.fill(RasterPath) and RasterGraphics.draw(RasterPath). |
class Resampler | Resampling of interleaved 8-bit band data, the two-pass fixed-point convolution of Pillow’s Resample.c. |
class TrueTypeFont | A scalable font read from the bytes of a TrueType file (.ttf, an OpenType .otf with TrueType outlines, or one face of a .ttc collection), drawn by RasterGraphics.drawString(String, double, double). |