当前您所在的位置:首页>翻译软件 条码 证书>条码软件

Dynamsoft Barcode Reader C/C ++ API for Mac

Dynamsoft Barcode Reader C/C ++ API for Mac

使用Dynamsoft Barcode Reader C/C ++ API for Mac

Dynamsoft Barcode Reader SDK为Mac提供C ++和C API。 您可以使用条形码API轻松创建Mac的条形码读取软件。在本文中,我将演示如何使用Mac的C ++条形码读取API在Mac OS上构建一维和二维条形码识别的命令行应用程序 X。

开始一个新文件

新建命令行工具

首先,让我们打开Xcode。

选择命令行工具作为项目模板,并在类型下选择C ++ stdc ++。 让我们将项目命名为BarcodeReaderDemo。

添加引用

在main.cpp中,请包括.H文件。

在我们的示例中,如果您在应用程序下安装了条形码阅读器,则路径将为“/ Applications / Dynamsoft / Barcode Reader 4.1 / Include / If_DBRP.h”。

#include

#include“/ Applications / Dynamsoft / Barcode Reader 4.1 / Include / If_DBRP.h”

复制主功能

接下来,插入下列代码到主功能

int  main  ( int  argc,   const  char *  argv[ ] )

{

   //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);

       

   return 0;

}

选择链接库

选择Targets - > BarcodeReaderDemo,单击信息按钮,在弹出的对话框中,addlibDynamsoftBarcodeReader.dylib依赖。

更新许可证和源映像

请在代码中分别使用有效值更新<您的映像文件完整路径>和<您的许可证密钥>。

对于图像路径,您可以在Images文件夹中使用AllSupportedBarcodeTypes.tif。

对于许可证密钥,请在BarcodeReaderTrialLic.txt中找到它。

const char * pszImageFile =“/ Applications / Dynamsoft / Barcode Reader 4.1 /

Images / AllSupportedBarcodeTypes.tif“;

                

现在你可以构建项目并运行。

条形码结果

请打开Terminal.app 并运行该app并确认是否可行

北京哲想软件有限公司