How to scan a barcode from a .Net stream
You can read a barcode from a stream (TIF/JPG or PDF) in C# using the following function to convert the stream into a byte array:
private static byte[] StreamToByteArray(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
…and then if ‘s’ is your stream scan for the barcode with code similar to:
SoftekBarcodeNet.BarcodeReader barcode = new SoftekBarcodeNet.BarcodeReader();
byte[] data = StreamToByteArray(s);
int nBarCodes = barcode.ScanBarCodeFromByteArray(data);
etc etc