LBarCode::Read

#include "ltwrappr.h"

L_INT LBarCode::Read (nBarType, pBarCode1D = NULL, pBarCodePDF = NULL)

L_INT nBarType;

/* barcode type flag */

pBARCODE1D pBarCode1D;

/* pointer to the BARCODE1D structure */

pBARCODEREADPDF pBarCodePDF;

/* pointer to the BARCODEREADPDF structure */

Searches for barcodes.

Parameter

Description

nBarType

Flag that specifies the barcode type and determines the function 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.

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.

Returns

>0

Total number of recognized bar codes.

<=0

An error occurred. Refer to Return Codes.

Comments

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.

The Linear barcodes are not supported in UNICODE.

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:

LBarCode::LBarCode, LBarCode::GetBarCodeDataItem, LBarCode::IsDuplicated, LBarCode::GetDuplicatedCount, LBarCode::GetFirstDuplicated, LBarCode::GetNextDuplicated, LBarCode::WriteExt, LBarCode::WriteExt2, Class Members

Topics:

Programming with LEADTOOLS Barcode

Barcode Function Functions: Reading BarCodes

Example

For complete sample code refer to BarCode demo.

L_INT TestBarCodeRead (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;
}