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.
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.
-
ClassDescriptionReads and writes JPEG files in pure Java.Reads and writes PNG files in pure Java.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.A linear or radial color gradient forRasterGraphics.setPaint(RasterPaint).Draws antialiased shapes, gradients and images into aRasterImage.A mutable image held in memory as 32-bit ARGB pixels.WhatRasterGraphicsfills with when it is not a single color: a gradient (RasterGradient) or your own pattern.A shape made of straight lines and quadratic and cubic Bezier curves, forRasterGraphics.fill(RasterPath)andRasterGraphics.draw(RasterPath).Resampling of interleaved 8-bit band data, the two-pass fixed-point convolution of Pillow'sResample.c.A scalable font read from the bytes of a TrueType file (.ttf, an OpenType.otfwith TrueType outlines, or one face of a.ttccollection), drawn byRasterGraphics.drawString(String, double, double).