VintaSoft Barcode .NET SDK v11.0
In This Topic
    How to draw barcode with specified size and resolution?
    In This Topic

    Example: Here is an example that shows how to draw barcode with specified size and resolution.

    Public Shared Sub TestDrawBarcode(filename As String)
            ' draw barcode with size 6 x 2 cm and resolution 300 dpi
            Using barcodeImage As Image = DrawBarcode(BarcodeType.Code128, "TESTBARCODE", 300, 6, 2, UnitOfMeasure.Centimeters)
                    ' save barcode image to a file
                    barcodeImage.Save(filename)
            End Using
    End Sub
    
    Public Shared Function DrawBarcode(barcode As BarcodeType, value As String, resolution As Single, width As Single, height As Single, units As UnitOfMeasure) As Image
            ' create the barcode writer
            Dim writer As New BarcodeWriter()
    
            ' set barcode writer settings
            writer.Settings.Barcode = barcode
            writer.Settings.Value = value
            writer.Settings.Resolution = resolution
            writer.Settings.PixelFormat = BarcodeImagePixelFormat.Bgr24
    
            ' return barcode image
            Return writer.GetBarcodeAsBitmap(width, height, UnitOfMeasure.Centimeters)
    End Function
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Barcode
    
    public static void TestDrawBarcode(string filename)
    {
        // draw barcode with size 6 x 2 cm and resolution 300 dpi
        using (System.Drawing.Image barcodeImage = DrawBarcode(
            Vintasoft.Barcode.BarcodeType.Code128,
            "TESTBARCODE",
            300,
            6,
            2,
            Vintasoft.Barcode.UnitOfMeasure.Centimeters))
        {
            // save barcode image to a file
            barcodeImage.Save(filename);
        }
    }
    
    public static System.Drawing.Image DrawBarcode(
        Vintasoft.Barcode.BarcodeType barcode,
        string value,
        float resolution,
        float width,
        float height,
        Vintasoft.Barcode.UnitOfMeasure units)
    {
        // create the barcode writer
        Vintasoft.Barcode.BarcodeWriter writer = new Vintasoft.Barcode.BarcodeWriter();
        
        // set barcode writer settings
        writer.Settings.Barcode = barcode;
        writer.Settings.Value = value;
        writer.Settings.Resolution = resolution;
        writer.Settings.PixelFormat = Vintasoft.Barcode.BarcodeImagePixelFormat.Bgr24;
    
        // return barcode image
        return writer.GetBarcodeAsBitmap(width, height, Vintasoft.Barcode.UnitOfMeasure.Centimeters);
    }