Back to Devexpress

QR Code

officefileapi-15144-barcode-generation-api-bar-code-types-qr-code.md

latest2.5 KB
Original Source

QR Code

  • Aug 14, 2024
  • 2 minutes to read

Short Description

A QR Code ( QR is the abbreviation for Quick Response ) is a two-dimensional code, readable by QR scanners, mobile phones with a camera, and smartphones. QR Code can encode textual, numeric and binary data.

Example

csharp
using DevExpress.Drawing;
using System.Text;
using DevExpress.BarCodes;
// ...

static void Main(string[] args)
{
    // Create a QR code.
    BarCode barCode = new BarCode();
    barCode.Symbology = Symbology.QRCode;
    barCode.CodeText = "https://www.devexpress.com";
    barCode.BackColor = Color.White;
    barCode.ForeColor = Color.Black;
    barCode.RotationAngle = 0;
    barCode.CodeBinaryData = Encoding.Default.GetBytes(barCode.CodeText);
    barCode.Options.QRCode.CompactionMode = QRCodeCompactionMode.Byte;
    barCode.Options.QRCode.ErrorLevel = QRCodeErrorLevel.Q;
    barCode.Options.QRCode.ShowCodeText = false;
    barCode.DpiX = 72;
    barCode.DpiY = 72;
    barCode.Module = 2f;

    // Save the barcode as an image.
    barCode.Save("BarCodeImage.png", DXImageFormat.Png);
    // Open the image in the default viewer.
    Process.Start(new ProcessStartInfo("BarCodeImage.png") { UseShellExecute = true });
}
vb
Imports DevExpress.Drawing
Imports System.Text
Imports DevExpress.BarCodes
' ...

Shared Sub Main(ByVal args() As String)
    ' Create a QR code.
    Dim barCode As New BarCode()
    barCode.Symbology = Symbology.QRCode
    barCode.CodeText = "https://www.devexpress.com"
    barCode.BackColor = Color.White
    barCode.ForeColor = Color.Black
    barCode.RotationAngle = 0
    barCode.CodeBinaryData = Encoding.Default.GetBytes(barCode.CodeText)
    barCode.Options.QRCode.CompactionMode = QRCodeCompactionMode.Byte
    barCode.Options.QRCode.ErrorLevel = QRCodeErrorLevel.Q
    barCode.Options.QRCode.ShowCodeText = False
    barCode.DpiX = 72
    barCode.DpiY = 72
    barCode.Module = 2F

    ' Save the barcode as an image.
    barCode.Save("BarCodeImage.png", DXImageFormat.Png)
    ' Open the image in the default viewer.
    Process.Start(New ProcessStartInfo("BarCodeImage.png") With {.UseShellExecute = True})
End Sub

See Also

BarCode

Symbology

QRCodeOptions

Version