How to read barcodes from an image in unmanaged memory?
In This Topic
Here is C#/VB.NET code that demonstrates how to read barcodes from image if image data are stored in an unmanaged memory.
/// <summary>
/// Reads barcodes from an image. Image data are stored in an unmanaged memory.
/// </summary>
/// <param name="reader">The barcode reader.</param>
/// <param name="width">The image width.</param>
/// <param name="height">The image height.</param>
/// <param name="stride">The image stride.</param>
/// <param name="format">The image format.</param>
/// <param name="pixelDataScan0">The Scan0 pointer to the image pixel data.</param>
public static Vintasoft.Barcode.IBarcodeInfo[] ReadBarcodes(
Vintasoft.Barcode.BarcodeReader reader, int width, int height, int stride,
System.Drawing.Imaging.PixelFormat format, IntPtr pixelDataScan0)
{
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, stride, format, pixelDataScan0))
{
// read barcodes
return reader.ReadBarcodes(bitmap);
}
}
''' <summary>
''' Reads barcodes from an image. Image data are stored in an unmanaged memory.
''' </summary>
''' <param name="reader">The barcode reader.</param>
''' <param name="width">The image width.</param>
''' <param name="height">The image height.</param>
''' <param name="stride">The image stride.</param>
''' <param name="format">The image format.</param>
''' <param name="pixelDataScan0">The Scan0 pointer to the image pixel data.</param>
Public Shared Function ReadBarcodes(reader As Vintasoft.Barcode.BarcodeReader, width As Integer, _
height As Integer, stride As Integer, format As System.Drawing.Imaging.PixelFormat, _
pixelDataScan0 As IntPtr) As Vintasoft.Barcode.IBarcodeInfo()
Using bitmap As New System.Drawing.Bitmap(width, height, stride, format, pixelDataScan0)
' read barcodes
Return reader.ReadBarcodes(bitmap)
End Using
End Function