I am trying to read a 3of9 barcode. 3of9 barcode Image the result that is giving me is inconstant but the location is still the same. (tried running that method multiple times same Image/barcode and same position) What I mean by inconstant is sometimes I am getting the value of the barcode ex. barcodesd.Length is not zero so it is getting the barcodesd[0].Value which is 25350111 and sometimes the barcodesd.Length = 0
here is my code:
public static string DecodeImg(System.Drawing.Bitmap img)
{
System.IO.MemoryStream data = new MemoryStream();
RasterImage srcImage = null;
try
{
BarcodeEngine engine = new BarcodeEngine();
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs();
img.Save(data, System.Drawing.Imaging.ImageFormat.Jpeg);
data.Seek(0, System.IO.SeekOrigin.Begin);
srcImage = codecs.Load(data);
BarcodeData[] barcodesd = engine.Reader.ReadBarcodes(srcImage, LeadRect.Empty, 0, BarcodeEngine.GetSupportedSymbologies(), null);
srcImage.Dispose();
if (barcodesd != null)
{
if (barcodesd.Length > 0)
return barcodesd[0].Value;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
data.Dispose();
if (srcImage != null)
srcImage.Dispose();
}
return "Unable to Read";
}