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.

  • RasterImage holds non-premultiplied ARGB pixels and rotates, flips, crops and resizes them.
  • RasterGraphics draws antialiased lines, rectangles, ellipses, arcs, polygons and Bezier paths (RasterPath), with transforms, clipping, alpha, gradients (RasterGradient) and images. Text goes through the RasterFont seam; TrueTypeFont reads TrueType fonts and embeds a default one, so text needs no font file.
  • Resampler is Pillow’s resampling convolution, byte for byte.
  • PngCodec and JpegCodec read 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 JpegCodecReads and writes JPEG files in pure Java.
class PngCodecReads and writes PNG files in pure Java.
interface RasterFontThe 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 RasterGradientA linear or radial color gradient for RasterGraphics.setPaint(RasterPaint).
class RasterGraphicsDraws antialiased shapes, gradients and images into a RasterImage.
class RasterImageA mutable image held in memory as 32-bit ARGB pixels.
interface RasterPaintWhat RasterGraphics fills with when it is not a single color: a gradient (RasterGradient) or your own pattern.
class RasterPathA shape made of straight lines and quadratic and cubic Bezier curves, for RasterGraphics.fill(RasterPath) and RasterGraphics.draw(RasterPath).
class ResamplerResampling of interleaved 8-bit band data, the two-pass fixed-point convolution of Pillow’s Resample.c.
class TrueTypeFontA 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).