Class PNGCanvas

All Implemented Interfaces:
Closeable, AutoCloseable, ByteArrayResult, Canvas

public class PNGCanvas extends Graphics2DCanvas implements ByteArrayResult
Canvas for generating PNG files.

PNGs are not an optimal file format for QR bills. Vector formats such a SVG or PDF are of better quality and use far less processing power to generate.

  • Constructor Details

    • PNGCanvas

      public PNGCanvas(double width, double height, int resolution, String fontFamilyList)
      Creates a new instance with the specified image size, resolution and font family.

      It is recommended to use at least 144 dpi for a readable result.

      The first font family in the list is used.

      Parameters:
      width - image width, in mm
      height - image height, in mm
      resolution - resolution of the result (in dpi)
      fontFamilyList - list of font families (comma separated, CSS syntax)
  • Method Details

    • toByteArray

      public byte[] toByteArray() throws IOException
      Description copied from interface: ByteArrayResult
      Gets the resulting graphics as a byte array.
      Specified by:
      toByteArray in interface ByteArrayResult
      Returns:
      the byte array
      Throws:
      IOException - thrown if the construction of the byte array fails
    • writeTo

      public void writeTo(OutputStream os) throws IOException
      Writes the resulting PNG image to the specified output stream.
      Parameters:
      os - the output stream
      Throws:
      IOException - thrown if the image cannot be written
    • saveAs

      public void saveAs(Path path) throws IOException
      Saves the resulting PNG image to the specified path.
      Parameters:
      path - the path to write to
      Throws:
      IOException - thrown if the image cannot be written
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class Graphics2DCanvas