Package net.codecrete.qrbill.canvas
Class PNGCanvas
java.lang.Object
net.codecrete.qrbill.canvas.AbstractCanvas
net.codecrete.qrbill.canvas.Graphics2DCanvas
net.codecrete.qrbill.canvas.PNGCanvas
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteArrayResult
,Canvas
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.codecrete.qrbill.canvas.Canvas
Canvas.LineStyle
-
Field Summary
Fields inherited from class net.codecrete.qrbill.canvas.AbstractCanvas
fontMetrics, MM_TO_PT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Saves the resulting PNG image to the specified path.byte[]
Gets the resulting graphics as a byte array.void
writeTo
(OutputStream os) Writes the resulting PNG image to the specified output stream.Methods inherited from class net.codecrete.qrbill.canvas.Graphics2DCanvas
addRectangle, closeSubpath, cubicCurveTo, fillPath, initGraphics, lineTo, moveTo, putText, setOffset, setTransformation, startPath, strokePath
Methods inherited from class net.codecrete.qrbill.canvas.AbstractCanvas
getAscender, getDescender, getLineHeight, getTextWidth, putTextLines, setupFontMetrics, splitLines
-
Constructor Details
-
PNGCanvas
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 mmheight
- image height, in mmresolution
- resolution of the result (in dpi)fontFamilyList
- list of font families (comma separated, CSS syntax)
-
-
Method Details
-
toByteArray
Description copied from interface:ByteArrayResult
Gets the resulting graphics as a byte array.- Specified by:
toByteArray
in interfaceByteArrayResult
- Returns:
- the byte array
- Throws:
IOException
- thrown if the construction of the byte array fails
-
writeTo
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
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classGraphics2DCanvas
-