Barcode Reader 如何使用 Visual C++创建条码识别程序

作者:控件中国网   出处:控件中国网   2015-08-10 10:46:44   阅读:8

Barcode Reader是Dynamsoft公司最新推出的一款一维和二维条码识别控件,可以识别多种类型的条形码,识别精确,支持多种C/C++,ActiveX/COM,.NET等多种平台和设备驱动,这里主要介绍如何使用VC++创建条码识别应用程序,具体如下:

1.创建一个空的Win32 Console Application应用程序,并命名为BarcodeReaderDemo ,在 main.cpp把 .H 和 .LIB 文件包含进去
#include <stdio.h>
#include "<relative path>/If_DBRP.h"
#ifdef _WIN64
#pragma comment(lib, "<relative path>/x64/DBRx64.lib")
#else
#pragma comment(lib, "<relative path>/x86/DBRx86.lib")
#endif
2.在main.cpp,Main函数里添加如下代码
int main(int argc, const char* argv[])
{
    //Define variables
 const char * pszImageFile = "<your image file full path>";
 int iIndex = 0;
 int iRet = -1;
       
    //Initialize license prior to any decoding
    CBarcodeReader reader;
 reader.InitLicense("<your license key here>");

    //Initialize ReaderOptions
 ReaderOptions ro = {0};  
 ro.llBarcodeFormat = OneD; //Expected barcode types to read.
 ro.iMaxBarcodesNumPerPage = 100; //Expected barcode numbers to read.
    reader.SetReaderOptions(ro);

    //Start decoding
    iRet = reader.DecodeFile(pszImageFile);

    //If not DBR_OK
 if (iRet != DBR_OK)
 {
  printf("Failed to read barcode: %d\r\n%s\r\n",iRet, GetErrorString(iRet));
  return iRet;
 }

    //If DBR_OK
 pBarcodeResultArray paryResult = NULL;
    reader.GetBarcodes(&paryResult);
 printf("%d total barcodes found. \r\n", paryResult->iBarcodeCount);
 for (iIndex = 0; iIndex < paryResult->iBarcodeCount; iIndex++)
 {
  printf("Result %d\r\n", iIndex + 1);
  printf("PageNum: %d\r\n", paryResult->ppBarcodes[iIndex]->iPageNum);
  printf("BarcodeFormat: %lld\r\n", paryResult->ppBarcodes[iIndex]->llFormat);
  printf("Text read: %s\r\n", paryResult->ppBarcodes[iIndex]->pBarcodeData);
 }

    //Finally release BarcodeResultArray
    CBarcodeReader::FreeBarcodeResults(&paryResult);
       
 return 0;
}
3.编译程序,并且复制DynamsoftBarcodeReaderx86.dll 和 DynamsoftBarcodeReaderx64.dll 到.Exe文件夹,就可以进行图片上条码的识别了

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat