Skip to main content
All docs
V26.1
  • BarcodeGenerator.ExportAsync(String, Encoding, Stream, DXImageFormat) Method

    Asynchronously exports a barcode image for the specified text to a stream, using the given encoding and image format.

    Namespace: DevExpress.Docs.Barcode

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

    Declaration

    public Task ExportAsync(
        string text,
        Encoding encoding,
        Stream stream,
        DXImageFormat format = null
    )

    Parameters

    Name Type Description
    text String

    The text to encode as a barcode.

    encoding Encoding

    The encoding to use for the text.

    stream Stream

    The stream to which the barcode image will be written.

    Optional Parameters

    Name Type Default Description
    format DXImageFormat null

    (Optional) The image format for the exported barcode. If null, the default format is used.

    Returns

    Type Description
    Task

    A task that represents the asynchronous export operation.

    Remarks

    The following code snippet encodes text to a QR code and exports it as an SVG image asynchronously:

    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 a QR code as an SVG image asynchronously.
            using (FileStream stream = new FileStream("D:\\qrcode_text.svg", FileMode.Create, FileAccess.Write)) {
                await generator.ExportAsync("https://example.com", Encoding.UTF8, stream, DXImageFormat.Svg);
            }
        }
    }
    
    See Also