#include "ltwrappr.h"
L_INT LBarCode::Read (nBarType, pBarCode1D = NULL, pBarCodePDF = NULL)
Searches for barcodes.
Flag that specifies the barcode type and determines the function's behavior. Possible values are:
Value | Meaning |
---|---|
BARCODE_LINEAR | [0] Search for linear barcodes. |
BARCODE_PDF | [2] Search for PDF barcodes. |
BARCODE_DATAMATRIX | [3] Search for Data Matrix barcodes. |
BARCODE_QR | [4] Search for QR barcodes. |
BARCODE_Aztec | [5] Search for Aztec barcodes. |
BARCODE_Maxi | [6] Search for Maxi barcodes. |
BARCODE_MicroQR | [7] Search for MicroQR barcodes. |
Pointer to the BARCODE1D structure. Pass NULL to use the default structure or if you do not want to search for linear barcodes.
Pointer to the BARCODEREADPDF structure. Pass NULL to use the default structure or if you do not want to search for PDF barcodes.
Value | Meaning |
---|---|
>0 | Total number of recognized barcodes. |
<=0 | An error occurred. Refer to Return Codes. |
Use this function to recognize barcode data.
The barcode read options must be set using LBarCode::SetReadOptions before calling LBarCode::Read. If the read options are not set, LBarCode::Read will return an error.
If the barcode type specified in nBarType does not correspond to the barcode type set in the barcode read options, this function returns an error. For example, if BARCODE_1D_EAN_13 is set in the read options as the barcode type, and LBarCode::Read is called with nBarType set to BARCODE_DATAMATRIX, this function will return an error.
The actual barcode data can be accessed through the LBarCode::GetBarCodeDataItem function.
To determine if a barcode element is duplicated or not, use the LBarCode::IsDuplicated function. If the barcode is duplicated, you can get the total number of duplicates for a specified barcode using the LBarCode::GetDuplicatedCount function. To get the first duplicate barcode, use the LBarCode::GetFirstDuplicated function. To get the next duplicate barcode, use the LBarCode::GetNextDuplicated function.
The LBarCode class will free the allocated storage for the barcode data array when the LBarCode::~LBarCode function is called.
Linear barcodes are not supported in UNICODE.
A barcode is composed of a start mark, data, and the end mark. Reading barcodes from left to right (passing BARCODE_DIR_LEFT_TO_RIGHT value to the nDirection member) or from right to left (passing BARCODE_DIR_RIGHT_TO_LEFT value to the nDirection member) will produce the same result in most cases, because the barcode reader engine recognizes the start and end marks, and handles the data accordingly.
For example, if BARCODE_DIR_LEFT_TO_RIGHT is passed and the user reads barcodes from left to right (the barcode is not rotated), the engine will recognize the start mark first, then the data, and finally the end mark.
But if the user reads barcodes from right to left (the barcode is rotated 180 degrees), the engine will first recognize the end mark, then read the (reverse-order) data, and then recognize the start mark. In this case, the engine will flip the data to normal (start/data/end) order.
For a table containing information useful when writing 1D barcode data, refer to Writing Linear 1D Barcodes.
For complete sample code refer to BarCode demo.
L_INT LBarCode_ReadExample (HWND hWnd, LBitmapBase &LeadBitmap)
{
LBarCode LeadBarCode;
BARCODE1D BarCode1D;
pBARCODEDATA pBarCodeData=NULL;
BARCODEREADOPT BarCodeReadOpt;
L_TCHAR szBuffer[256];
L_INT nBarTotal;
L_INT i;
L_INT nRet;
memset(&BarCode1D, 0, sizeof(BARCODE1D));
memset(&BarCodeReadOpt, 0, sizeof(BARCODEREADOPT));
LeadBarCode.SetBitmap(&LeadBitmap);
if (!LeadBarCode.IsValid())
return FAILURE;
nRet = LeadBarCode.GetReadOptions(&BarCodeReadOpt);
if (nRet != SUCCESS)
return nRet;
BarCodeReadOpt.nMultipleMax = 10;
BarCodeReadOpt.nUnits = BARCODE_INCHES;
BarCodeReadOpt.ulFlags = BARCODE_MARKERS | BARCODE_USECOLORS;
BarCodeReadOpt.ulSearchType = BARCODE_1D_EAN_13 | BARCODE_1D_EAN_8;
BarCodeReadOpt.bUseRgn = TRUE;
BarCodeReadOpt.BarColor.uStructSize = sizeof(BARCODECOLOR);
BarCodeReadOpt.BarColor.dwColorBar = RGB(0, 0, 255);
BarCodeReadOpt.BarColor.dwColorSpace = RGB(255, 0, 0);
SetRect(&BarCodeReadOpt.rcSearch, 0, 0, 0, 0);
nRet = LeadBarCode.SetReadOptions(&BarCodeReadOpt);
if (nRet != SUCCESS)
return nRet;
BarCode1D.uStructSize = sizeof(BARCODE1D);
BarCode1D.bErrorCheck = TRUE;
BarCode1D.nGranularity = 9;
BarCode1D.nMinLength = 4;
BarCode1D.nDirection = BARCODE_DIR_LEFT_TO_RIGHT;
nBarTotal = LeadBarCode.Read(BARCODE_LINEAR, &BarCode1D);
if (nBarTotal > 0)
{
pBarCodeData = LeadBarCode.GetBarCodeDataItem(0);
if (!pBarCodeData)
return FAILURE;
}
memset(szBuffer, 0, sizeof(szBuffer));
wsprintf(szBuffer, TEXT("Total Barcode Symbols Found is: %d\n\n"), nBarTotal);
MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK);
for (i=0; i< nBarTotal; i++)
{
memset(szBuffer, 0, sizeof(szBuffer));
wsprintf(szBuffer, TEXT("Barcode No. %d\nData is %hs\nType %s\nUnits %s\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"),
i, pBarCodeData[i].pszBarCodeData, (pBarCodeData[i].ulType == BARCODE_1D_EAN_13) ? TEXT("EAN 13") : TEXT("EAN 8"), TEXT("INCHES"),
pBarCodeData[i].rcBarLocation.left,
pBarCodeData[i].rcBarLocation.top,
abs(pBarCodeData[i].rcBarLocation.right - pBarCodeData[i].rcBarLocation.left),
abs(pBarCodeData[i].rcBarLocation.bottom - pBarCodeData[i].rcBarLocation.top));
MessageBox(hWnd, szBuffer, TEXT("BarCode Info."), MB_OK);
}
return SUCCESS;
}