I'm trying to use the EZTwain scanning library to retrieve barcodes from a scanned image, and I'm getting a return value of -4 when I try to call EZTwain.BARCODE_Recognize(IntPtr, int, int)
, which there is no description for in the EZTwain user guide.
In the EZTwain user guide, it lists some return values that are used as error codes as you can see here.
BARCODE_Recognize
int BARCODE_Recognize(HDIB hdib, int nMaxCount, int nType)
Find and recognize barcodes in the given image.
Don't look for more than nMaxCount barcodes (-1 means 'any number').
Expect barcodes of the specified type (-1 means 'any supported type')
You can add or 'or' together barcode types, to tell the recognizer to look for more
than one symbology. Return values:
>0 n barcodes found
0 no barcodes found
-1 barcode services not available.
-3 invalid or null image
There is no -4 return value listed, and I don't know where else to look because the user guide is the only thing that I know that is available for documentation on this library.
This is the code I'm using when I get the code of -4 returned.
I do call EZTwain_SetVendorKey but left that out for obvious reasons.
I'm wondering if it has something to do with the IntPtr
I'm passing? The documentation says Call BARCODE_Recognize, passing it the handle of the image to search, the
maximum number of barcode patches to find, and a mask of the barcode
types (symbologies) to look for. If this function finds any barcodes, it returns
a positive integer = the count of symbols (barcodes) found.
I pass the IntPtr
i create using the image, and -1, -1 to find all barcodes in the image, using all of the barcode types.
public static string GetBarcode(Bitmap image, out BarcodeType barcodeType, int percentThatCanBeNonWhitish = 2, int pixelTolerance = 10)
{
// initialize barcodeType to appease the compiler
barcodeType = BarcodeType.NotBarcode;
BitmapData bd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite,
image.PixelFormat);
List<string> barcodes = new List<string>();
EZTwain.BARCODE_SelectEngine(EZTwain.EZBAR_ENGINE_DOSADI);
EZTwain.BARCODE_SetDirectionFlags(EZTwain.EZBAR_HORIZONTAL | EZTwain.EZBAR_VERTICAL);
IntPtr imgPtr = image.GetHbitmap();
if (EZTwain.DIB_IsBlank(imgPtr, .002) == true)
{
// Do nothing, the page is blank
}
else if (EZTwain.BARCODE_IsEngineAvailable(EZTwain.EZBAR_ENGINE_DOSADI))
{
int count;
count = EZTwain.BARCODE_Recognize(imgPtr, -1, -1);
for (int i = 0; i < count; i++)
{
barcodes.Add(EZTwain.BARCODE_Text(i));
}
}
if (barcodes.Count != 0)
{
string barcode = barcodes[0];
// sets the type to coversheet if it is blank, else it uses ProcessBarcodeType()
barcodeType = image.IsBlank(percentThatCanBeNonWhitish, pixelTolerance) ? BarcodeType.CoversheetBarcode : ProcessBarcodeType(barcode);
return barcode;
}
else
{
return null;
}
}
Does anyone know what this error code means? And if so, where did you discover what it meant?