Dynamsoft Barcode Reader C C++ API

在Windows里使用Dynamsoft Barcode Reader C++ API 在Windows桌面应用程序Dynamsoft的C ++条形码阅读器库为Windows允许你几乎立即嵌入一维和二维条码阅读功能。我将演示如何使用C ++条形码阅读API的Windows构建一个Win32控制台应用程序条形码识别。 开始一个新文件 新的控制台应用程序 首先,让我们打开Visual Studio。 通过Visual C ++> Win32创建一个空的Win32控制台应用程序项目。 让我们把它命名为BarcodeReaderC ++ API 添加引用 按照本指南,首先,引用.H和.LIB文件。 为了更容易,让我们从包含文件夹和lib文件夹从安装目录复制到项目。 在此处更改相对路径。 #include #include "/If_DBRP.h" #ifdef _WIN64 #pragma comment ( lib, "/x64/DBRx64.lib" ) #else #pragma comment ( lib, "/x86/DBRx86.lib" ) #endif 复制主函数 接下来,将以下代码插入主函数。   //Define variables const char * pszImageFile = ""; int iIndex = 0; int iRet = -1;         //Initialize license prior to any decoding CBarcodeReader reader; reader.InitLicense("");   //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); 升级源图片 改变图片路径。我将会用一个例子图片Change the image path. I am going to use a sample image from the installation folder. Copy the file path, add the escape character, and then the file name. Change the path to "C:\\Program Files (x86)\\Dynamsoft\\Barcode Reader 4.1\\Images\\AllSupportedBarcodeTypes.tif".   const char * pszImageFile = "C:\\Program Files (x86)\\Dynamsoft\\Barcode  Reader 4.1\\Images\\AllSupportedBarcodeTypes.tif";               Build the project. Build Succeeded. 复制条码DLL 转到安装目录,在Components \ C_C ++ \ Redist文件夹下,复制这两个DLL - DynamsoftBarcodeReaderx86.dll和DynamsoftBarcodeReaderx64.dll。 将其粘贴到与BarcodeReaderC ++ API.exe相同的文件夹中,默认情况下,该文件位于解决方案的Debug文件夹下。 按Ctrl + F5运行项目。 好。 我们已经识别所有的条形码。 查看代码 现在,让我们快速浏览代码。 首先,我们定义包括图像路径的变量。 然后我们配置许可证信息。 使用此片段,我们初始化条形码阅读选项,如条形码类型,以及每页读取多少条形码。 调用DecodeFile方法来解码条形码。 如果找到多个条形码,我们使用循环逐个打印出结果。 //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); } 记住要释放BarcodeResultArray 最后但也同样重要,我们需要释放BarcodeResultArray。 请注意这一步很重要。 //Finally release BarcodeResultArray CBarcodeReader::FreeBarcodeResults(&paryResult); 其他条形码阅读功能 最后,如果要从图像的特定区域解码条形码,则有一个DecodeFileRect方法。 Dynamsoft的条形码读取器SDK还支持从设备无关位图(也称为DIB),缓冲区和base64字符串读取条形码。

咨询

  • 点击这里给我发消息 发邮件给我们

搜索