VintaSoft Barcode .NET SDK 15.1: Руководство для .NET разработчика
В этом разделе
    Генерация изображения штрих-кода в виде объекта SkiaSharp.SKBitmap
    В этом разделе
    Пример: Вот пример, который показывает, как создать изображение штрих-кода в виде объекта SkiaSharp.SKBitmap.
    /// <summary>
    /// Allows to generate barcode using SkiaSharp libraly.
    /// </summary>
    public static class SkiaSharpBitmapBarcodeGenerator
    {
        /// <summary>
        /// Initializes the <see cref="SkiaSharpBitmapBarcodeGenerator"/> class.
        /// </summary>
        static SkiaSharpBitmapBarcodeGenerator()
        {
            // initialize Vintasoft.Barcode.SkiaSharp assembly - must be called only once
            // initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.SkiaSharpAssembly.Init();
        }
    
        /// <summary>
        /// Returns the Code128 barcode as <see cref="SkiaSharp.SKBitmap"/>.
        /// </summary>
        /// <param name="value">The barcode value.</param>
        /// <returns>An <see cref="SkiaSharp.SKBitmap"/> object.</returns>
        public static SkiaSharp.SKBitmap 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 SkiaSharp.SKBitmap
                return Vintasoft.Barcode.SkiaSharpExtensions.GetBarcodeAsSKBitmap(barcodeWriter);
            }
        }
    }
    
    ''' <summary>
    ''' Allows to generate barcode using SkiaSharp libraly.
    ''' </summary>
    Public NotInheritable Class SkiaSharpBitmapBarcodeGenerator
        Private Sub New()
        End Sub
        ''' <summary>
        ''' Initializes the <see cref="SkiaSharpBitmapBarcodeGenerator"/> class.
        ''' </summary>
        Shared Sub New()
            ' initialize Vintasoft.Barcode.SkiaSharp assembly - must be called only once
            ' initialization is necessary if text value of barcode should be drawn on barcode image
            Vintasoft.Barcode.SkiaSharpAssembly.Init()
        End Sub
    
        ''' <summary>
        ''' Returns the Code128 barcode as <see cref="SkiaSharp.SKBitmap"/>.
        ''' </summary>
        ''' <param name="value">The barcode value.</param>
        ''' <returns>An <see cref="SkiaSharp.SKBitmap"/> object.</returns>
        Public Shared Function GetCode128BarcodeAsBitmap(value As String) As SkiaSharp.SKBitmap
            ' 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 SkiaSharp.SKBitmap
                Return Vintasoft.Barcode.SkiaSharpExtensions.GetBarcodeAsSKBitmap(barcodeWriter)
            End Using
        End Function
    End Class