VintaSoft Barcode .NET SDK 14.0: Documentation for .NET developer
In This Topic
    Get barcode image as System.Windows.Media.Imaging.BitmapSource object
    In This Topic
    Example: Here is an example that shows how to generate barcode as a System.Windows.Media.Imaging.BitmapSource object.
    /// <summary>
    /// Allows to generate barcode using WPF libraly.
    /// </summary>
    public static class WpfBitmapBarcodeGenerator
    {
        /// <summary>
        /// Initializes the <see cref="WpfBitmapBarcodeGenerator"/> class.
        /// </summary>
        static WpfBitmapBarcodeGenerator()
        {
            // initialize Vintasoft.Barcode.Wpf assembly - must be called only once
            // initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.WpfAssembly.Init();
        }
    
        /// <summary>
        /// Returns the Code128 barcode as <see cref="System.Windows.Media.Imaging.BitmapSource"/>.
        /// </summary>
        /// <param name="value">The barcode value.</param>
        /// <returns>A <see cref="System.Windows.Media.Imaging.BitmapSource"/> object.</returns>
        public static System.Windows.Media.Imaging.BitmapSource 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.Windows.Media.Imaging.BitmapSource
                return Vintasoft.Barcode.WpfExtensions.GetBarcodeAsBitmapSource(barcodeWriter);
            }
        }
    }
    
    ''' <summary>
    ''' Allows to generate barcode using WPF libraly.
    ''' </summary>
    Public NotInheritable Class WpfBitmapBarcodeGenerator
        Private Sub New()
        End Sub
        ''' <summary>
        ''' Initializes the <see cref="WpfBitmapBarcodeGenerator"/> class.
        ''' </summary>
        Shared Sub New()
            ' initialize Vintasoft.Barcode.Wpf assembly - must be called only once
            ' initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.WpfAssembly.Init()
        End Sub
    
        ''' <summary>
        ''' Returns the Code128 barcode as <see cref="System.Windows.Media.Imaging.BitmapSource"/>.
        ''' </summary>
        ''' <param name="value">The barcode value.</param>
        ''' <returns>A <see cref="System.Windows.Media.Imaging.BitmapSource"/> object.</returns>
        Public Shared Function GetCode128BarcodeAsBitmap(value As String) As System.Windows.Media.Imaging.BitmapSource
            ' 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.Windows.Media.Imaging.BitmapSource
                Return Vintasoft.Barcode.WpfExtensions.GetBarcodeAsBitmapSource(barcodeWriter)
            End Using
        End Function
    End Class