Class PNGCanvas
Canvas for generating PNG files.
Inherited Members
Namespace: Codecrete.SwissQRBill.PixelCanvas
Assembly: Codecrete.SwissQRBill.Generator.dll
Syntax
public class PNGCanvas : AbstractCanvas, ICanvas, IDisposable
Remarks
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
Constructors
| Edit this page View SourcePNGCanvas(double, double, int, string)
Initializes a new instance of a PNG canvas with the given size, resolution and font family.
The QR bill will be drawn in the bottom left corner of the image.
It is recommended to use at least 144 dpi for a readable result.
Declaration
public PNGCanvas(double width, double height, int resolution, string fontFamilyList)
Parameters
| Type | Name | Description |
|---|---|---|
| double | width | The image width, in mm. |
| double | height | The image height, in mm. |
| int | resolution | The resolution of the image to generate (in pixels per inch). |
| string | fontFamilyList | A list font family names, separated by comma (same syntax as for CSS). The first font family will be used. |
Methods
| Edit this page View SourceAddRectangle(double, double, double, double)
Adds a rectangle to the open path.
Declaration
public override void AddRectangle(double x, double y, double width, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The rectangle's left position (in mm). |
| double | y | The rectangle's top position (in mm). |
| double | width | The rectangle's width (in mm). |
| double | height | The rectangle's height (in mm). |
Overrides
| Edit this page View SourceClose()
Closes this instance and frees resources.
After a call to this method, the canvas can no longer be used for drawing.
Declaration
protected void Close()
CloseSubpath()
Closes the current subpath. The next path operation will implicitly open a new subpath.
Declaration
public override void CloseSubpath()
Overrides
| Edit this page View SourceCubicCurveTo(double, double, double, double, double, double)
Adds a cubic BeziƩr curve to the open path going from the previous point to the specified position. Two control points determine the curve.
Declaration
public override void CubicCurveTo(double x1, double y1, double x2, double y2, double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x1 | The x-coordinate of first control point. |
| double | y1 | The y-coordinate of first control point. |
| double | x2 | The x-coordinate of second control point. |
| double | y2 | The y-coordinate of second control point. |
| double | x | The x-coordinate of position. |
| double | y | The y-coordinate of position. |
Overrides
| Edit this page View SourceDispose(bool)
Frees and releases resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | indicates whether the method is called from a |
Overrides
| Edit this page View SourceFillPath(int, bool)
Fills the current path and discards it.
Declaration
public override void FillPath(int color, bool smoothing = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | color | The fill color (expressed similar to HTML, e.g. 0xffffff for white). |
| bool | smoothing |
|
Overrides
| Edit this page View SourceLineTo(double, double)
Adds a line segment to the open path from the previous point to the specified position.
Declaration
public override void LineTo(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The x-coordinate of position. |
| double | y | The y-coordinate of position. |
Overrides
| Edit this page View SourceMoveTo(double, double)
Moves the current point of the open path to the specified position.
Declaration
public override void MoveTo(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The x-coordinate of position. |
| double | y | The y-coordinate of position. |
Overrides
| Edit this page View SourcePutText(string, double, double, int, bool)
Draws text to the canvas.
The text position refers to the left most point on the text's baseline.
Declaration
public override void PutText(string text, double x, double y, int fontSize, bool isBold)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to draw. |
| double | x | The x position of the text's start (in mm). |
| double | y | The y position of the text's top (in mm). |
| int | fontSize | The font size (in pt). |
| bool | isBold | Flag indicating if the text is in bold or regular weight. |
Overrides
| Edit this page View SourceSaveAs(string)
Writes the resulting graphics as a PNG image to the specified file path.
The canvas can no longer be used for drawing after calling this method.
Declaration
public void SaveAs(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path (file name) to write to. |
SetTransformation(double, double, double, double, double)
Sets a translation, rotation and scaling for the subsequent operations.
Before a new translation is applied, the coordinate system is reset to it's original state.
The transformations are applied in the order translation, rotation, scaling.
Declaration
public override void SetTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY)
Parameters
| Type | Name | Description |
|---|---|---|
| double | translateX | The translation in x direction (in mm). |
| double | translateY | The translation in y direction (in mm). |
| double | rotate | The rotation angle, in radians. |
| double | scaleX | The scale factor in x direction (1.0 = no scaling). |
| double | scaleY | The scale factor in y direction (1.0 = no scaling). |
Overrides
| Edit this page View SourceStartPath()
Starts a path that can be filled or stroked.
Declaration
public override void StartPath()
Overrides
| Edit this page View SourceStrokePath(double, int, LineStyle, bool)
Strokes the current path and discards it.
Declaration
public override void StrokePath(double strokeWidth, int color, LineStyle lineStyle = LineStyle.Solid, bool smoothing = true)
Parameters
| Type | Name | Description |
|---|---|---|
| double | strokeWidth | The stroke width (in pt). |
| int | color | The stroke color (expressed similar to HTML, e.g. 0xffffff for white). |
| LineStyle | lineStyle | The line style |
| bool | smoothing |
|
Overrides
| Edit this page View SourceToByteArray()
Gets the resulting graphics encoded as a PNG image in a byte array.
The canvas can no longer be used for drawing after calling this method.
Declaration
public override byte[] ToByteArray()
Returns
| Type | Description |
|---|---|
| byte[] | The byte array containing the PNG image |
Overrides
| Edit this page View SourceWriteTo(Stream)
Writes the resulting graphics as a PNG image to the specified stream.
The canvas can no longer be used for drawing after calling this method.
Declaration
public void WriteTo(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to write to. |