L_BarCodeRead
#include "ltbar.h"
L_INT EXT_FUNCTION L_BarCodeRead(pBitmap, prcSearch, ulSearchType, nUnits, ulFlags, nMultipleMaxCount, pBarCode1D, pBarCodePDF, pBarCodeColor, ppBarCodeData)
pBITMAPHANDLE pBitmap; |
/* pointer to the bitmap handle */ |
RECT L_FAR * prcSearch; |
/* pointer to the area rectangle to search for*/ |
L_UINT32 ulSearchType; |
/* the type of barcode to search for */ |
L_INT nUnits; |
/* unit of measure */ |
L_UINT32 ulFlags; |
/* flags that determine the function behavior */ |
L_INT nMultipleMaxCount; |
/* maximum number of barcodes to search */ |
pBARCODE1D pBarCode1D; |
/* pointer to the BARCODE1D structure */ |
pBARCODEREADPDF pBarCodePDF; |
/* pointer to the BARCODEREADPDF structure */ |
pBARCODECOLOR pBarCodeColor; |
/* pointer to the BARCODECOLOR structure */ |
pBARCODEDATA L_FAR * ppBarCodeData; |
/* address of pointer to the BARCODEDATA structure */ |
Searches for barcodes within the specified area.
Parameter |
Description |
|
pBitmap |
Pointer to the bitmap handle referencing the bitmap that holds the image data. |
|
prcSearch |
Pointer to the rectangle that contains the search area for the barcodes. Pass NULL to search the whole image. If this parameter is NULL and the image does not have a region, the entire image will be searched. If this parameter is NULL and the image does have a region, only the region will be searched. |
|
ulSearchType |
Type of barcode for which to search. You can combine values when appropriate among the same group values, by using a bitwise OR ( | ). Possible values are: |
|
|
Value |
Meaning |
|
Linear Barcode: |
|
|
BARCODE_1D_EAN_13 |
[0x00000001] To read EAN 13 type. |
|
BARCODE_1D_EAN_8 |
[0x00000002] To read EAN 8 type. |
|
BARCODE_1D_UPC_A |
[0x00000004] To read UPC version A type. |
|
BARCODE_1D_UPC_E |
[0x00000008] To read UPC version E type. |
|
BARCODE_1D_CODE_3_OF_9 |
[0x00000010] To read Code 3 of 9 (Code 39) type. |
|
BARCODE_1D_CODE_128 |
[0x00000020] To read Code 128 type. |
|
BARCODE_1D_CODE_I2_OF_5 |
[0x00000040] To read Interleaved 2 of 5 type. |
|
BARCODE_1D_CODA_BAR |
[0x00000080] To read CODABAR type. |
|
BARCODE_1D_UCCEAN_128 |
[0x00000100] To read UCCEAND 128 type |
|
BARCODE_1D_CODE_93 |
[0x00000200] To read Code 93 type. |
|
BARCODE_1D_READ_ANYTYPE |
[0x00000FF0] To enable searching of all linear barcode types. |
|
PDF Barcodes: |
|
|
BARCODE_PDF417 |
[0x00002000] To read PDF417 type. |
|
QR Barcodes: |
|
|
BARCODE_QR_CODE |
[0x00100000] To read QR barcodes. |
|
Data Matrix Barcode: |
|
|
BARCODE_DM_READ_SQUARE |
[0x00010000] To read square Data Matrix symbols. |
|
BARCODE_DM_READ_RECTANGLE |
[0x00020000] To read rectangular Data Matrix symbols. |
|
BARCODE_DM_READ_SMALL |
[0x00040000] To read small Data Matrix symbols. |
nUnits |
Unit of measure. Possible values are: |
|
|
Value |
Meaning |
|
BARCODE_SCANLINES_PER_PIXELS |
[0] The rectangle search area is measured in pixels. |
|
BARCODE_INCHES |
[1] The rectangle search area is measured in inches. You must multiply the search area by 100. (i.e. to specify 1 inch set this to 100) |
|
BARCODE_MILLIMETERS |
[2] The rectangle search area is measured in mm. |
ulFlags |
Processing options. You can combine values when appropriate, by using a bitwise OR ( | ). The following values are used only when you want to search for linear barcodes. Pass 0 to get the default. Possible values are: |
|
|
Value |
Meaning |
|
BARCODE_MARKERS |
[0x0001] Enables the reading of barcodes that have start and end markers. |
|
BARCODE_SEARCH_BLOCK |
[0x0002] Search for barcodes by moving up or down through the rectangle until the first character is read or there is no barcode found. |
|
BARCODE_USECOLORS |
[0x0200] Enable searching for color barcodes. The colors are used as the exact bar and space colors for searching for the barcode. |
|
BARCODE_RETURNCHECK |
[0x1000] When setting this bit, then the check character will return in all cases, whether BARCODE1D.bErrorCheck is enabled or not. |
|
BARCODE_RETURNCORRUPT |
[0x080] Enables the engine to return the area that an un-readable PDF417 symbol was located. |
|
BARCODE_RETURN_FOUR_POINTS |
[0x00002000] Enable return of four corners and not bounding rectangle. |
|
BARCODE_DM_FORCE_INVERT |
[0x00000800] Force the Data Matrix read to search for reversed color symbols even if non-inverted color symbols were found. |
|
BARCODE_DM_FASTFIND_DISABLE |
[0x00001000] Disable fast find feature when reading Data Matrix symbols. Fast find is automatically disabled when reading small symbols. |
|
BARCODE_PDF_READ_RETURN_PARTIAL |
[0x01000000] Return PDF417 data even if ECC does not succeed. |
|
BARCODE_PDF_READ_MODE_0 |
[0x0000] Basic Channel Mode :No transmission of symbology ID, No escape doubling, Macro PDF is illegal.ECI is illegal, Reserved code words are illegal. |
|
BARCODE_PDF_READ_MODE_1 |
[0x1000] Extended Channel Mode.Transmit] L1 symbology ID. Escape doubling. Macro PDF is transmitted. ECI is transmitted. Reserved code words are transmitted. |
|
BARCODE_PDF_READ_MODE_2 |
[0x2000] Basic Channel Mode. Transmit ] L2 symbology ID. No escape doubling. Macro PDF is illegal. ECI is illegal. Reserved code words are illegal. |
|
BARCODE_PDF_READ_MODE_3_BASIC |
[0x3000] Basic Channel Mode. Transmit ] L0 symbology ID. No escape doubling. Macro PDF is illegal. ECI is illegal. Reserved code words are illegal. |
|
BARCODE_PDF_READ_MODE_3_EXTENDED |
[0x7000] Extended Channel Mode. Transmit ] L0 symbology ID. Escape doubling. Macro PDF is transmitted. ECI is transmitted in GLI format. Reserved code words transmitted. |
|
BARCODE_PDF_READ_MACRO_OPTION_0 |
[0x00010000] Enable the return of the optional macro ‘File Name’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_1 |
[0x00020000] Enable the return of the optional macro ‘Segment Count’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_2 |
[0x00040000] Enable the return of the optional macro ‘Time Stamp’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_3 |
[0x00080000] Enable the return of the optional macro ‘Sender’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_4 |
[0x00100000] Enable the return of the optional macro ‘Addressee’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_5 |
[0x00200000] Enable the return of the optional macro ‘File Size’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_6 |
[0x00400000] Enable the return of the optional macro ‘Checksum’ field. |
|
BARCODE_PDF_READ_MACRO_OPTION_79AZ |
[0x00800000] Enable the return of all optional macro fields 7 to 9 and A to Z. |
nMultipleMaxCount |
Specifies the maximum number of barcodes to search. Pass 0 to read all barcodes in a specified search area. |
|
pBarCode1D |
Pointer to the BARCODE1D structure. Pass NULL to use the default structure or if you don't want to search for linear barcodes. |
|
pBarCodePDF |
Pointer to the BARCODEREADPDF structure. Pass NULL to use the default structure or if you don't want to search for PDF barcodes. |
|
ppBarCodeData |
Address of the pointer to the BARCODEDATA structure, the function will automatically allocate an array of BARCODEDATA structures using the total number of barcodes found. |
|
pBarCodeColor |
Pointer to the BARCODECOLOR structure. Pass NULL to search for barcode using the default colors. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
This function supports all bitmaps currently supported by LEADTOOLS.
Use this function to recognize barcode data.
To determine if a barcode element is duplicated or not, use L_BarCodeIsDuplicated function. If the barcode is duplicated, you can get it using L_BarCodeGetDuplicated and to get the next duplicated barcode use L_BarCodeGetNextDuplicated.
If you know the index of a duplicated barcode, you can get the first duplicate of that barcode using L_BarCodeGetFirstDuplicated.
Since the function allocates storage to hold a Barcode array, you must free this storage by calling L_BarCodeFree.
When the BARCODE_USECOLORS flag is set, then this function will use the pBarCodeColor parameter, otherwise the function will ignore it and use the default colors of black for bars and white for spaces are used.
Using colors does not apply for 1 bit per pixel images.
The BARCODE_USECOLORS is used with all barcode kinds.
The BARCODE_RETURNCHECK flag used only with reading linear barcodes.
The smallest Data Matrix symbol size is 40 pixels by 40 pixels. It can be read using BARCODE_DM_READ_SMALL since this enables the reading of Data Matrix symbols that are between 20 to 40 pixels in size.
The Linear barcodes are not supported in UNICODE.
When calling the L_BarCodeRead function with the BARCODE_RETURN_FOUR_POINTS flag set, the BARCODEDATA.rcBarLocation member will be updated with the coordinates of the four corners of the barcode rather than the coordinates of the bounding rectangle. These coordinates are encoded values and must be decoded before they can be used. The following example shows how to decode the four-point corner values:
POINT p1, p2, p3, p4;
int nStartX = BarCodeData.rcBarLocation.left;
int nStartY = BarCodeData.rcBarLocation.top;
int nWidth = BarCodeData.rcBarLocation.right - nStartX;
int nHeight = BarCodeData.rcBarLocation.bottom - nStartY;
p1.x = (nStartX & 0xffff);
p1.y = (nStartX >> 16);
p2.x = (nStartY & 0xffff);
p2.y = (nStartY >> 16);
p3.x = (nWidth & 0xffff);
p3.y = (nWidth >> 16);
p4.x = (nHeight & 0xffff);
p4.y = (nHeight >> 16);
Required DLLs and Libraries
LTBAR For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application |
See Also
Functions: |
L_BarCodeWriteExt, L_BarCodeFree, L_BarCodeIsDuplicated, L_BarCodeGetDuplicated, L_BarCodeGetNextDuplicated, L_BarCodeVersionInfo, L_BarCodeGetFirstDuplicated, L_BarCodeWriteExt2 |
Topics: |
Example
For complete sample code refer to MFCBar32 demo.
L_INT TestBarCodeRead (HWND hWnd, pBITMAPHANDLE pBitmap)
{
BARCODE1D BarCode1D;
pBARCODEDATA pBarCodeData=NULL;
BARCODECOLOR BarColor;
L_TCHAR szBuffer[256];
L_INT nBarTotal;
L_INT i;
L_INT nRet;
memset(&BarCode1D, 0, sizeof(BARCODE1D));
BarColor.dwColorBar = RGB(0, 0, 255);
BarColor.dwColorSpace = RGB(255, 0, 0);
BarCode1D.bErrorCheck = TRUE;
BarCode1D.nGranularity = 9;
BarCode1D.nMinLength = 4;
BarCode1D.nDirection = BARCODE_DIR_LEFT_TO_RIGHT;
nRet = L_BarCodeRead(pBitmap, NULL, BARCODE_1D_EAN_13 | BARCODE_1D_EAN_8,
BARCODE_INCHES, BARCODE_MARKERS | BARCODE_USECOLORS, 10, &BarCode1D, NULL, &BarColor, &pBarCodeData);
if (nRet == SUCCESS)
{
nBarTotal = pBarCodeData[0].nTotalCount;
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);
}
L_BarCodeFree(&pBarCodeData);
}
else
{
memset(szBuffer, 0, sizeof(szBuffer));
wsprintf(szBuffer, TEXT("An error occurred in L_BarCodeRead,\nError No. = %d\n"), nRet);
MessageBox(hWnd, szBuffer, TEXT("Error!"), MB_OK);
}
return nRet;
}