Skip to content

Advanced usage QR Code renderers

Raffael Herrmann edited this page Apr 25, 2024 · 37 revisions
  1. Introduction to the "QR Code Renderers"
  2. Overview of the different Renderers
    2.1. QRCode-Renderer in detail
    2.2. AsciiQRCode-Renderer in detail
    2.3. Base64QRCode-Renderer in detail
    2.4. BitmapByteQRCode-Renderer in detail
    2.5. PngByteQRCode-Renderer in detail
    2.6. SvgQRCode-Renderer in detail
    2.7. UnityQRCode-Renderer in detail
    2.8. XamlQRCode-Renderer in detail
    2.9. PostscriptQRCode-Renderer in detail
    2.10. PdfByteQRCode-Renderer in detail
    2.11. ArtQRCode-Renderer in detail

1. Introduction to the "QR Code Renderers"

As explained in the architectural overview, the QRCoder separates data/information from output/representation. So in data/core layer you create the QR Code information:

CodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The payload aka the text which should be encoded.", QRCodeGenerator.ECCLevel.Q);

Now you have to bring this information into a representation you like - or better said - you have to convert this information into the output format you like. Therefore you can use the so called "QR Code renderers". This are classes of the QRCoder which help you to represent that QrCodeData the way you prefer. Each renderer-class has a function called "GetGraphic" which returns the graphical representation of the QR Code.

Before we have a look at each of the renderers, let's have a quick look onto the following comparison table which shows the benefits of each of the renderer classes.

2. Overview of the different Renderers

The following table gives an overview of which renderer is available on which target platforms and which datatype it generates.

Name Output Format .NET3.5+ .NET4.0+ .NET5.0 .NET5.0-windows .NET6.0 .NET6.0-windows .NETStandard1.3+ .NETStandard2.0+
QRCode Bitmap-object (System.Drawing.Bitmap)
AsciiQrCode String (QR Code encoded as ASCII chars)
Base64QRCode String (QR Code encoded as Base64) (1)
BitmapByteQRCode Byte-Array containing raw Bitmap
PngByteQRCode Byte-Array containing raw PNG image
SvgQRCode String (QR Coded as SVG vector graphic)
UnityQRCode (via QRCoder.Unity nuget-package) Texture2D (UnityEngine.Texture2D)
XamlQRCode (via QRCoder.Xaml nuget-package) DrawingImage (for usage in WPF, Silverlight, etc.)
PostscriptQRCode String (QR code encoded as PS/EPS string.)
PdfByteQRCode Byte-Array containing raw PDF document
ArtQRCode Bitmap-object (System.Drawing.Bitmap)

(1) On platforms other than Windows only PNG is supported in Base64QRCode

2.1 QRCode-Renderer in detail

Classname/Classfile: QRCode/QRCode.cs

When to use?

Use it if you want a pixel-based image (=Bitmap) and if you are working with .NET Framework. Use it if you want to show the QR Code in your app, save the QR Code as image file or deliver the QR Code as download.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

Parameter table

There are four different overloads:

Overload 1 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn

Overload 2 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Overload 3 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Overload 4 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
icon Bitmap null If null, then ignored. If set, the Bitmap is drawn in the middle of the QR Code
iconSizePercent int 15 Value from 1-99. Sets how much % of the QR Code will be covered by the icon
iconBorderWidth int 6 Width of the border which is drawn around the icon. Minimum: 1
drawQuietZones bool true If true a white border is drawn around the whole QR Code
iconBackgroundColor Color? null Defines the background color of the icon. If null(=default) the value of lightColoris used. (Icon background is only rendered and thus iconBackgroundColor is only used, if parameter icon != null and iconBorderWidth > 0.)

Good to know

This renderer is the way to go, if you want to draw an icon onto the QR Code.In most cases this renderer fits the needs very well.

2.2 AsciiQRCode-Renderer in detail

Classname/Classfile: ASCIIQRCode / ASCIIQRCode.cs

When to use?

Useful for web-, retro- and console-environments. By use of this encoder you get a QR code encoded as string just build out of chars. By default UTF-8 block symbols are used.

Trivia: The renderer is called Ascii renderer, although it uses characters from the Utf-8 character set by default. The idea behind this is that the renderer uses a text-based graphical representation that is reminiscent of classic Ascii art. Naming it Utf8QrCode was rejected in the design phase, as it would be difficult to deduce from this name what type of return value the renderer has.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
AsciiQRCode qrCode = new AsciiQRCode(qrCodeData);
string qrCodeAsAsciiArt = qrCode.GetGraphic(1);

Parameter table

There are three different overloads:

Overload 1 (Return type: string)

Parameter name Type Default Description
repeatPerModule int Number of repeated darkColorString/whiteSpaceString per module. (Must be 1 or greater.)
darkColorString string ██ String for use as dark color modules. In case of string make sure whiteSpaceString has the same length.
whiteSpaceString string String for use as white modules (whitespace). In case of string make sure darkColorString has the same length.
drawQuietZones bool true If true a white border is "drawn" around the whole QR Code
endOfLine string \n End of line separator.

Overload 2 (Functionname: GetLineByLineGraphic, Return type: string[])

Parameter name Type Default Description
repeatPerModule int Number of repeated darkColorString/whiteSpaceString per module.
darkColorString string ██ String for use as dark color modules. In case of string make sure whiteSpaceString has the same length.
whiteSpaceString string String for use as white modules (whitespace). In case of string make sure darkColorString has the same length.
drawQuietZones bool true If true a white border is "drawn" around the whole QR Code.

Overload 3 (Functionname: GetGraphicSmall, Return type: string)

Parameter name Type Default Description
drawQuietZones bool true If true a border is "drawn" around the whole QR Code.
invert bool false If set to true, light- and dark color will be switched.
endOfLine string \n End of line separator.

Good to know

If you set darkColorString or whiteSpaceString you have to ensure that they are both of the same length. Also you should keep in mind that this type of rendering only works when shown in a so called "Monospace" font. If you need a smaller representation than GetGraphic with repeatPerModule: 1, use GetGraphicSmall which compresses two module lines into one character line each.

2.3 Base64QRCode-Renderer in detail

Classname/Classfile: Base64QRCode / Base64QRCode.cs

When to use?

Usually very helpful in web and database environments. You can embed the Base64 images into html code, easily trafer them via HTTP requests or write them into databases without any hassle.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
Base64QRCode qrCode = new Base64QRCode(qrCodeData);
string qrCodeImageAsBase64 = qrCode.GetGraphic(20);

Parameter table

There are four different overloads:

Overload 1 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn

Overload 2 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code
imgType Base64QRCode.ImageType Base64QRCode.ImageType.Png Sets the image format of the image which is encoded in the Base64 string

Overload 3 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code
imgType Base64QRCode.ImageType Base64QRCode.ImageType.Png Sets the image format of the image which is encoded in the Base64 string

Overload 4 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
icon Bitmap null If null, then ignored. If set, the Bitmap is drawn in the middle of the QR Code
iconSizePercent int 15 Value from 1-99. Sets how much % of the QR Code will be covered by the icon
iconBorderWidth int 6 Width of the border which is drawn around the icon. Minimum: 1
drawQuietZones bool true If true a white border is drawn around the whole QR Code
imgType Base64QRCode.ImageType Base64QRCode.ImageType.Png Sets the image format of the image which is encoded in the Base64 string

Good to know

The string returned by the GetGraphic-method just contains the image as Base64 string. It does not contain any HTML tags, etc. If you like to embed the image for example, you have to add the img-tag. E.g.

//...
var imgType = Base64QRCode.ImageType.Jpeg;
Base64QRCode qrCode = new Base64QRCode(qrCodeData);
string qrCodeImageAsBase64 = qrCode.GetGraphic(20,Color.Black, Color.White, true, imgType);
var htmlPictureTag =  $"<img alt=\"Embedded QR Code\" src=\"data:image/{imgType.ToString().ToLower()};base64,{qrCodeImageAsBase64}\" />";

2.4 BitmapByteQRCode-Renderer in detail

Classname/Classfile: BitmapByteQRCode / BitmapByteQRCode.cs

When to use?

When using the PCL version of the QRCoder (e.g. in mobile projects) this is, besides PngByteQRCode, the only available renderer. It returns the QR code as byte-array which contains a Bitmap graphic. Since many of the platforms where the PCL library is available have different implementations of Bitmap class, but nearly any platform can create an image from byte[], this is some way of dealing with images cross-platforms.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData);
byte[] qrCodeAsBitmapByteArr = qrCode.GetGraphic(20);

//From here on, you can implement your platform-dependent byte[]-to-image code 

//e.g. Windows 10 - Full .NET Framework
Bitmap bmp;
using (var ms = new MemoryStream(qrCodeAsBitmapByteArr))
{
    qrCodeImage = new Bitmap(ms);
}

//e.g. Windows 10 Universal App (UAP)
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
    using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0)))
    {
        writer.WriteBytes(qrCodeImage);
        await writer.StoreAsync();
    }
    var image = new BitmapImage();
    await image.SetSourceAsync(stream);

    imageViewer.Source = image;
}

Parameter table

There are two overloads:

Overload 1 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn

Overload 2 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorRgba byte[] The color of the dark modules, as RGB array
lightColorRgba byte[] The color of the light modules, as RGB array

Good to know

Since this method shall be 100% platform independent the Bitmap in the byte[] is created manually byte by byte. So this renderer doesn't offer any fancy parameters right now. If you are an Bitmap expert feel free to improve the code. If you aren't but want a cool QR code, use the QR code module matrix and create your own renderer.

2.5 PngByteQRCode-Renderer in detail

Classname/Classfile: PngByteQRCode / PngByteQRCode.cs

When to use?

When using the PCL version of the QRCoder (e.g. in mobile projects) this is, besides BitmapByteQRCode, the available renderer. It returns the QR code as byte-array which contains a PNG graphic. Since many of the platforms where the PCL library is available have different implementations of Imaging classes, but nearly any platform can create an image from byte[] (or write a byte-array to file), this is some way of dealing with images cross-platforms.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
PngByteQRCode qrCode = new PngByteQRCode(qrCodeData);
byte[] qrCodeAsPngByteArr = qrCode.GetGraphic(20);

//From here on, you can implement your platform-dependent byte[]-to-image code 

//e.g. Windows 10 - Full .NET Framework
Bitmap bmp;
using (var ms = new MemoryStream(qrCodeAsPngByteArr))
{
    qrCodeImage = new Bitmap(ms);
}

//e.g. Windows 10 Universal App (UAP)
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
    using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0)))
    {
        writer.WriteBytes(qrCodeAsPngByteArr);
        await writer.StoreAsync();
    }
    var image = new BitmapImage();
    await image.SetSourceAsync(stream);

    imageViewer.Source = image;
}

Parameter table

There are two overloads:

Overload 1 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Overload 2 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorRgba byte[] The color of the dark modules, as RGB(A) array
lightColorRgba byte[] The color of the light modules, as RGB(A) array
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Good to know

Since this method shall be 100% platform independent the Png in the byte[] is created manually byte by byte. So this renderer doesn't offer any fancy parameters right now. If you are an Png expert feel free to improve the code. If you aren't but want a cool QR code, use the QR code module matrix and create your own renderer.

2.6 SvgQRCode-Renderer in detail

Classname/Classfile: SvgQRCode / SvgQRCode.cs

When to use?

Use this if you want to print the QR code in a huge size or when dealing with scalable (in sense of screensize) web applications. The SvgQRCode returns a scalable vector graphic which never gets blurry by its nature.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
SvgQRCode qrCode = new SvgQRCode(qrCodeData);
string qrCodeAsSvg = qrCode.GetGraphic(20);

Parameter table

There are six overloads:

Overload 1 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size

Overload 2 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the SVG viewbox
drawQuietZones bool true If true a white border is drawn around the whole QR Code
sizingMode SizingMode SizingMode.WidthHeightAttribute Changes how the size attributes of main <svg>-tag are created. Either width="xxx" height="xxx" (=SizingMode.WidthHeightAttribute) or viewBox="0 0 xxx xxx" (=SizingMode.ViewBoxAttribute) is used.
logo SvgLogo null An optional logo (svg or bitmap) to be rendered on the QR code

Overload 3 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code
sizingMode SizingMode SizingMode.WidthHeightAttribute Changes how the size attributes of main <svg>-tag are created. Either width="xxx" height="xxx" (=SizingMode.WidthHeightAttribute) or viewBox="0 0 xxx xxx" (=SizingMode.ViewBoxAttribute) is used.
logo SvgLogo null An optional logo (svg or bitmap) to be rendered on the QR code

Overload 4 (Return type: string)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code
sizingMode SizingMode SizingMode.WidthHeightAttribute Changes how the size attributes of main <svg>-tag are created. Either width="xxx" height="xxx" (=SizingMode.WidthHeightAttribute) or viewBox="0 0 xxx xxx" (=SizingMode.ViewBoxAttribute) is used.
logo SvgLogo null An optional logo (svg or bitmap) to be rendered on the QR code

Overload 5 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the SVG viewbox
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code
sizingMode SizingMode SizingMode.WidthHeightAttribute Changes how the size attributes of main <svg>-tag are created. Either width="xxx" height="xxx" (=SizingMode.WidthHeightAttribute) or viewBox="0 0 xxx xxx" (=SizingMode.ViewBoxAttribute) is used.
logo SvgLogo null An optional logo (svg or bitmap) to be rendered on the QR code

Overload 6 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the SVG viewbox
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code
sizingMode SizingMode SizingMode.WidthHeightAttribute Changes how the size attributes of main <svg>-tag are created. Either width="xxx" height="xxx" (=SizingMode.WidthHeightAttribute) or viewBox="0 0 xxx xxx" (=SizingMode.ViewBoxAttribute) is used.
logo SvgLogo null An optional logo (svg or bitmap) to be rendered on the QR code

Good to know

The string returned just contains the plain SVG. You can save it to file via StreamWriter-class or File.WriteAllText-method or you can embed into a website. But don't forget to write the correct tags around the SVG string. (Have a look here.)

2.7 UnityQRCode-Renderer in detail

Classname/Classfile: (external) See QRCoder.Unity-repository

When to use?

Use this renderer if you are working on an Unity-based app or game. This renderer return a Texture2D object for easier handling. It saves you some time, compared to the other renders.

How to use it - simple way

Install via Nuget: PM> Install-Package QRCoder.Unity
(QRCoder.Unity@nuget)

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
UnityQRCode qrCode = new UnityQRCode(qrCodeData);
Texture2D qrCodeAsTexture2D = qrCode.GetGraphic(20);

Parameter table

There are 3 overloads:

Overload 1 (Return type: Texture2D)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn

Overload 2 (Return type: Texture2D)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation

Overload 3 (Return type: Texture2D)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor UnityEngine.Color The color of the dark/black modules
lightColor UnityEngine.Color The color of the light/white modules

Good to know

This renderer is some kind of experimental. There are some reports that it sometimes is buggy on iOS devices, whilst Android, Windows and Linux should be working fine. So please test your project in an appropriate manner when using this renderer.

2.8 XamlQRCode-Renderer in detail

Classname/Classfile: XamlQRCode / XamlQRCode.cs

When to use?

Use this if you want to print the QR code in an XAML application (e.g. WPF, Silverlight). The XamlQRCode returns a scalable vector XAML object tree which never gets blurry by its nature.

How to use it - simple way

Install via Nuget: PM> Install-Package QRCoder.Xaml
(QRCoder.Xaml@nuget)

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
XamlQRCode qrCode = new XamlQRCode(qrCodeData);
DrawingImage qrCodeAsXaml = qrCode.GetGraphic(20);

Parameter table

There are five overloads:

Overload 1 (Return type: System.Windows.Media.DrawingImage)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size

Overload 2 (Return type: System.Windows.Media.DrawingImage)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size
drawQuietZones bool If true a white border is drawn around the whole QR Code

Overload 3 (Return type: System.Windows.Media.DrawingImage)

Parameter name Type Default Description
viewBox Size Size of the SVG viewbox
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Overload 4 (Return type: System.Windows.Media.DrawingImage)

Parameter name Type Default Description
pixelsPerModule int The pixel per b/w QR code module. This x module count = ViewBox size
darkColorHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Overload 5 (Return type: System.Windows.Media.DrawingImage)

Parameter name Type Default Description
viewBox Size Size of the SVG viewbox
darkBrush Brush The brush of the dark/black modules
lightBrush Brush The brush of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code

Good to know

The object tree returned can be assigned to an System.Windows.Controls.Image (<Image> in XAML) element's Source property. In the MVVM approach, the Source property can be bound to a model's string property and QR generation code can be implemented as an IValueConverter to convert a string value to QR code and return the System.Windows.Media.DrawingImage generated.

The <Image> element uses anti-aliased rendering by default, which makes the readability of a QR code worse. In order to display it with aliased rendering, set the RenderOptions.EdgeMode attached property to "Aliased".

2.9 PostscriptQRCode-Renderer in detail

Classname/Classfile: PostscriptQRCode / PostscriptQRCode.cs

When to use?

Use this if you want to print the QR code on a postscript printer or if you want to create a pdf file.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
PostscriptQRCode qrCode = new PostscriptQRCode(qrCodeData);
string qrCodeAsPostscript = qrCode.GetGraphic(20);

Parameter table

There are six overloads:

Overload 1 (Return type: string)

Parameter name Type Default Description
pointsPerModule int The point per b/w QR code module. This x module count = ViewBox size
epsMode bool false If true, create the file as Encapsulated Postscript (EPS)

Overload 2 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the Postscript viewbox
drawQuietZones bool true If true a white border is drawn around the whole QR Code
epsMode bool false If true create the file as Encapsulated Postscript (EPS)

Overload 3 (Return type: string)

Parameter name Type Default Description
pointsPerModule int The point per b/w QR code module. This x module count = ViewBox size
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code
epsMode bool false If true create the file as Encapsulated Postscript (EPS)

Overload 4 (Return type: string)

Parameter name Type Default Description
pointsPerModule int The point per b/w QR code module. This x module count = ViewBox size
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code
epsMode bool false If true create the file as Encapsulated Postscript (EPS)

Overload 5 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the Postscript viewbox
darkColor Color The color of the dark/black modules
lightColor Color The color of the light/white modules
drawQuietZones bool true If true a white border is drawn around the whole QR Code
epsMode bool false If true create the file as Encapsulated Postscript (EPS)

Overload 6 (Return type: string)

Parameter name Type Default Description
viewBox Size Size of the Postscript viewbox
darkColorHtmlHex string The color of the dark/black modules in hex (e.g. #000000) representation
lightColorHtmlHex string The color of the light/white modules in hex (e.g. #ffffff) representation
drawQuietZones bool true If true a white border is drawn around the whole QR Code
epsMode bool false If true create the file as Encapsulated Postscript (EPS)

Good to know

The string returned just contains the plain Postscript. You can save it to file via StreamWriter-class or File.WriteAllText-method.

2.10 PdfByteQRCode-Renderer in detail

Classname/Classfile: PdfByteQRCode / PdfByteQRCode.cs

When to use?

This renderer returns the QR code as byte-array which contains a PDF document. It is available on all platforms that support System.Drawing (e.g. .NET Framework >= 3.5, .NET Standard 2.0, ...) but isn't supported in .NET Standard 1.1 environments. Since many of the platforms have different implementations of PDF classes, but any platform can write a byte[] into a file, this is some way of dealing with PDFs cross-platforms.

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
PdfByteQRCode qrCode = new PdfByteQRCode(qrCodeData);
byte[] qrCodeAsPdfByteArr = qrCode.GetGraphic(20);

//From here on, you can implement your platform-dependent byte[]-to-(PDF-)file code 

Parameter table

There are two overloads:

Overload 1 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn

Overload 2 (Return type: byte[])

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColorHtmlHex string The color of the dark modules, as hex string e.g. #000000
lightColorHtmlHex string The color of the light modules, as hex string e.g. #ffffff
dpi int 150 DPI (dots per inch) resolution of the PDF document
jpgQuality long 85 Quality of the QR code graphic inside the PDF. From 1 (bad) to 100 (perfect).

Good to know

n/a

2.11 ArtQRCode-Renderer in detail

Classname/Classfile: QRCode/ArtQRCode.cs

When to use?

Use it if you want a pixel-based image (=Bitmap) with a more "artistic" style. You can set background images and define how the module are rendered. (As default they will be rendered as dots/circular).

How to use it - simple way

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
ArtQRCode qrCode = new ArtQRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(10);

Parameter table

There are three different overloads:

Overload 1 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int Amount of px each dark/light module of the QR code shall take place in the final QR code image

Overload 2 (Return type: Bitmap)

Parameter name Type Default Description
backgroundImage Bitmap null A bitmap object that will be used as background picture

Overload 3 (Return type: Bitmap)

Parameter name Type Default Description
pixelsPerModule int The pixel size each b/w module is drawn
darkColor Color Color of the dark modules
lightColor Color Color of the light modules
backgroundColor Color Color of the background
backgroundImage Bitmap null A bitmap object that will be used as background picture
pixelSizeFactor double 1.0 Value between 0.0 to 1.0 that defines how big the module dots are. The bigger the value, the less round the dots will be.
drawQuietZones bool true If true a white border is drawn around the whole QR Code
quietZoneRenderingStyle QuietZoneStyle QuietZoneStyle.Dotted Defines how the quiet zones shall be rendered. (Dotted or flat/filled.)
backgroundImageStyle BackgroundImageStyle BackgroundImageStyle.DataAreaOnly Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone
finderPatternImage Bitmap null Optional image that should be used instead of the default finder patterns

Good to know

This renderer allows the creation of visually appealing/beautiful QR codes, but it should be noted that the official QRCode standard does not provide for such a form. Depending on the background image used or if the pixelSizeFactor-value is too small, the QRCode may be recognized worse or not at all. This risk cannot be avoided and is the responsibility of the respective developer who includes the ArtQRCode in his/her application.

Clone this wiki locally