VintaSoft Barcode .NET SDK 15.0: Руководство для .NET разработчика
В этом разделе
    Генерация изображения штрих-кода в виде объекта System.Drawing.Bitmap
    В этом разделе
    Пример: Вот пример, который показывает, как создать изображение штрих-кода в виде объекта System.Drawing.Bitmap.

    /// <summary>
    /// Allows to generate barcode using System.Drawing libraly.
    /// </summary>
    public static class GdiBitmapBarcodeGenerator
    {
        /// <summary>
        /// Initializes the <see cref="GdiBitmapBarcodeGenerator"/> class.
        /// </summary>
        static GdiBitmapBarcodeGenerator()
        {
            // initialize Vintasoft.Barcode.Gdi assembly - must be called only once
            // initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.GdiAssembly.Init();
        }
    
        /// <summary>
        /// Returns the Code128 barcode as <see cref="System.Drawing.Bitmap"/>.
        /// </summary>
        /// <param name="value">The barcode value.</param>
        /// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
        public static System.Drawing.Bitmap GetCode128BarcodeAsBitmap(string value)
        {
            // create the barcode writer
            using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
            {
                // set barcode writer settings
                barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Code128;
                barcodeWriter.Settings.Value = value;
    
                // get a barcode image as System.Drawing.Bitmap
                return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
            }
        }
    }
    
    ''' <summary>
    ''' Allows to generate barcode using System.Drawing libraly.
    ''' </summary>
    Public NotInheritable Class GdiBitmapBarcodeGenerator
        Private Sub New()
        End Sub
        ''' <summary>
        ''' Initializes the <see cref="GdiBitmapBarcodeGenerator"/> class.
        ''' </summary>
        Shared Sub New()
            ' initialize Vintasoft.Barcode.Gdi assembly - must be called only once
            ' initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.GdiAssembly.Init()
        End Sub
    
        ''' <summary>
        ''' Returns the Code128 barcode as <see cref="System.Drawing.Bitmap"/>.
        ''' </summary>
        ''' <param name="value">The barcode value.</param>
        ''' <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
        Public Shared Function GetCode128BarcodeAsBitmap(value As String) As System.Drawing.Bitmap
            ' create the barcode writer
            Using barcodeWriter As New Vintasoft.Barcode.BarcodeWriter()
                ' set barcode writer settings
                barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Code128
                barcodeWriter.Settings.Value = value
    
                ' get a barcode image as System.Drawing.Bitmap
                Return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter)
            End Using
        End Function
    End Class