Skip to main content
All docs
V26.1
  • BarcodeGenerator.ExportToImageAsync(Byte[], DXImageFormat) Method

    Asynchronously generates a barcode image for the specified binary data.

    Namespace: DevExpress.Docs.Barcode

    Assembly: DevExpress.Docs.Barcode.v26.1.dll

    Declaration

    public Task<DXImage> ExportToImageAsync(
        byte[] binaryData,
        DXImageFormat format
    )

    Parameters

    Name Type Description
    binaryData Byte[]

    The binary data to encode as a barcode.

    format DXImageFormat

    The format of the generated image.

    Returns

    Type Description
    Task<DXImage>

    A task that represents the asynchronous operation. The result contains the generated barcode image.

    Remarks

    The following code snippet encodes binary data to a QR code and exports it as a PNG image asynchronously using the DXImage class:

    using DevExpress.Docs;
    using DevExpress.Docs.Barcode;
    using DevExpress.Drawing;
    using System.Drawing;
    
    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,
            };
    
            // Create binary data to encode.
            byte[] data = { 0x48, 0x65, 0x6C, 0x6C, 0x6F };
    
            using (BarcodeGenerator generator = new BarcodeGenerator(qrOptions)) {
    
                // Export binary data as a barcode image asynchronously.
                DXImage image = await generator.ExportToImageAsync(data, DXImageFormat.Png);
                // Save the barcode image to a file.
                using (FileStream stream = new FileStream("D:\\qrcode.png", FileMode.Create, FileAccess.Write)) {
                    image.Save(stream);
                }
            }
        }
    }
    
    See Also