Class PdfImage
java.lang.Object
com.codename1.pdf.PdfImage
An image to draw on a PDF page, built from encoded JPEG or PNG bytes or from ARGB pixels. Works without the UI layer, so a server can use it.
A JPEG is embedded as it is, without decoding. A PNG is decoded and its transparency kept as a soft mask.
PdfDocument doc = new PdfDocument();
PdfCanvas canvas = doc.addPage(PdfPageSize.A4).getCanvas();
PdfImage logo = PdfImage.create(Util.readInputStream(CN.getResourceAsStream("/logo.png")));
canvas.drawImage(logo, 36, 36, 120, 120 * logo.getHeight() / logo.getWidth());
-
Method Summary
Modifier and TypeMethodDescriptionstatic PdfImagecreate(byte[] encoded) An image from the bytes of a JPEG or PNG file, told apart by their signatures.static PdfImagecreate(int[] argb, int width, int height) An image from pixels0xAARRGGBB, row by row from the top.intThe height in pixels.intgetWidth()The width in pixels.
-
Method Details
-
create
An image from the bytes of a JPEG or PNG file, told apart by their signatures. ThrowsIOExceptionfor any other format.- Throws:
IOException
-
create
An image from pixels0xAARRGGBB, row by row from the top. -
getWidth
public int getWidth()The width in pixels. -
getHeight
public int getHeight()The height in pixels.
-