Package com.codename1.backend.image


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.