Skip to main content
All docs
V26.1
  • BarcodeGenerator.ExportToImage(String, Encoding) 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

    public DXImage ExportToImage(
        string text,
        Encoding encoding
    )

    Parameters

    Name Type Description
    text String

    The text to encode as a barcode.

    encoding Encoding

    The encoding to use for the text.

    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.
            DXImage svgImage = generator.ExportToImage("https://example.com", Encoding.UTF8);
    
            // Save the barcode image to a file.
            using (FileStream stream = new FileStream("D:\\qrcode.png", FileMode.Create, FileAccess.Write)) {
                svgImage.Save(stream, DXImageFormat.Png);
            }
        }
    }
    
    See Also