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
| Improve this Doc View SourcePNGCanvas(Double, Double, Int32, 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 |
---|---|---|
System.Double | width | The image width, in mm. |
System.Double | height | The image height, in mm. |
System.Int32 | resolution | The resolution of the image to generate (in pixels per inch). |
System.String | fontFamilyList | A list font family names, separated by comma (same syntax as for CSS). The first font family will be used. |
Methods
| Improve this Doc 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 |
---|---|---|
System.Double | x | The rectangle's left position (in mm). |
System.Double | y | The rectangle's top position (in mm). |
System.Double | width | The rectangle's width (in mm). |
System.Double | height | The rectangle's height (in mm). |
Overrides
| Improve this Doc 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
| Improve this Doc 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 |
---|---|---|
System.Double | x1 | The x-coordinate of first control point. |
System.Double | y1 | The y-coordinate of first control point. |
System.Double | x2 | The x-coordinate of second control point. |
System.Double | y2 | The y-coordinate of second control point. |
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
Overrides
| Improve this Doc View SourceDispose(Boolean)
Frees and releases resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | indicates whether the method is called from a |
Overrides
| Improve this Doc View SourceFillPath(Int32, Boolean)
Fills the current path and discards it.
Declaration
public override void FillPath(int color, bool smoothing = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | color | The fill color (expressed similar to HTML, e.g. 0xffffff for white). |
System.Boolean | smoothing |
|
Overrides
| Improve this Doc 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 |
---|---|---|
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
Overrides
| Improve this Doc 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 |
---|---|---|
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
Overrides
| Improve this Doc View SourcePutText(String, Double, Double, Int32, Boolean)
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 |
---|---|---|
System.String | text | The text to draw. |
System.Double | x | The x position of the text's start (in mm). |
System.Double | y | The y position of the text's top (in mm). |
System.Int32 | fontSize | The font size (in pt). |
System.Boolean | isBold | Flag indicating if the text is in bold or regular weight. |
Overrides
| Improve this Doc 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 |
---|---|---|
System.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 |
---|---|---|
System.Double | translateX | The translation in x direction (in mm). |
System.Double | translateY | The translation in y direction (in mm). |
System.Double | rotate | The rotation angle, in radians. |
System.Double | scaleX | The scale factor in x direction (1.0 = no scaling). |
System.Double | scaleY | The scale factor in y direction (1.0 = no scaling). |
Overrides
| Improve this Doc View SourceStartPath()
Starts a path that can be filled or stroked.
Declaration
public override void StartPath()
Overrides
| Improve this Doc View SourceStrokePath(Double, Int32, LineStyle, Boolean)
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 |
---|---|---|
System.Double | strokeWidth | The stroke width (in pt). |
System.Int32 | color | The stroke color (expressed similar to HTML, e.g. 0xffffff for white). |
LineStyle | lineStyle | The line style |
System.Boolean | smoothing |
|
Overrides
| Improve this Doc 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 |
---|---|
System.Byte[] | The byte array containing the PNG image |
Overrides
| Improve this Doc 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 |
---|---|---|
System.IO.Stream | stream | The stream to write to. |