Генерация изображения штрих-кода в виде объекта Vintasoft.Imaging.VintasoftBitmap
В этом разделе
Пример: Вот пример, который показывает, как создать изображение штрих-кода в виде объекта Vintasoft.Imaging.VintasoftBitmap.
/// <summary>
/// Allows to generate barcode as bitmap.
/// </summary>
public static class BitmapBarcodeGenerator
{
/// <summary>
/// Initializes the <see cref="BitmapBarcodeGenerator"/> class.
/// </summary>
static BitmapBarcodeGenerator()
{
// 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="Vintasoft.Imaging.VintasoftBitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="Vintasoft.Imaging.VintasoftBitmap"/> object.</returns>
public static Vintasoft.Imaging.VintasoftBitmap 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 Vintasoft.Imaging.VintasoftBitmap
return barcodeWriter.GetBarcodeAsVintasoftBitmap();
}
}
}
''' <summary>
''' Allows to generate barcode as bitmap.
''' </summary>
Public NotInheritable Class BitmapBarcodeGenerator
Private Sub New()
End Sub
''' <summary>
''' Initializes the <see cref="BitmapBarcodeGenerator"/> 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="Vintasoft.Imaging.VintasoftBitmap"/>.
''' </summary>
''' <param name="value">The barcode value.</param>
''' <returns>A <see cref="Vintasoft.Imaging.VintasoftBitmap"/> object.</returns>
Public Shared Function GetCode128BarcodeAsBitmap(value As String) As Vintasoft.Imaging.VintasoftBitmap
' 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 Vintasoft.Imaging.VintasoftBitmap
Return barcodeWriter.GetBarcodeAsVintasoftBitmap()
End Using
End Function
End Class