officefileapi-15191-barcode-generation-api-bar-code-options.md
The library allows you to set options specific for each code type and generate an image for use in your application or for inserting into a document.
When generating an image, the library allows you to set its orientation, color, quality, and also allows you to specify whether or not an image displays a bar code text. You can include top and bottom captions with arbitrary text formatted using font, color and alignment options.
Options common for all bar codes (BarCode.BackColor, BarCode.ForeColor, BarCode.RotationAngle etc.) are accessible via the properties of the BarCode object.
Options specific to a certain symbology are accessible via the properties of a BarCodeOptions object exposed by the BarCode.Options property.
The code sample below generates a bar code and specifies its options:
using System.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", System.Drawing.Imaging.ImageFormat.Png);
// Open the image in the default viewer.
Process.Start(new ProcessStartInfo("BarCodeImage.png") { UseShellExecute = true });
}
Imports System.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", System.Drawing.Imaging.ImageFormat.Png)
' Open the image in the default viewer.
Process.Start(New ProcessStartInfo("BarCodeImage.png") With {.UseShellExecute = True})
End Sub
See Also