BarcodeGenerator.ExportToImage(String, Encoding, DXImageFormat) Method
Generates a barcode image for the supplied text using the specified encoding.
Namespace: DevExpress.Docs.Barcode
Assembly: DevExpress.Docs.Barcode.v26.1.dll
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| text | String | The text to encode as a barcode. |
| encoding | Encoding | The encoding to use for the text. |
Optional Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| format | DXImageFormat | null | The format of the generated image. |
Returns
| Type | Description |
|---|---|
| DXImage | The generated barcode image. |
Remarks
The following code snippet encodes text to a QR code and exports it as a PNG image using the DXImage class:
using DevExpress.Docs;
using DevExpress.Docs.Barcode;
using DevExpress.Drawing;
using System.Drawing;
using System.Text;
namespace ConsoleApp1;
public class Program {
public static async Task Main(string[] _) {
// Configure QR code options.
QRCodeOptions qrOptions = new QRCodeOptions {
ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H,
CompactionMode = QRCodeCompactionMode.Auto,
IncludeQuietZone = false,
Version = QRCodeVersion.Version10,
ModuleSize = 40,
BackColor = Color.LightGray,
ShowText = false,
Padding = new Padding(5),
BorderWidth = 1,
BorderColor = Color.Blue,
Width = 500,
Height = 500,
};
using BarcodeGenerator generator = new BarcodeGenerator(qrOptions);
// Export text to a barcode image with UTF8 encoding and PNG format.
DXImage svgImage = generator.ExportToImage("https://example.com", Encoding.UTF8, DXImageFormat.Png);
// Save the barcode image to a file.
using (FileStream stream = new FileStream("D:\\qrcode.png", FileMode.Create, FileAccess.Write)) {
svgImage.Save(stream);
}
}
}
See Also