📄 sample.cpp
字号:
#include <stdlib.h>#include <stdio.h>#include <string.h>#include "PtAPI.h"void AddSlash( char* FileName );void ShowBarCodeInfo( PTTOTALBARCODEINFO* pBar );int main(){ char FileName[200]; printf( "\nPlease enter the image file to be decoded such as: ../image/QR_1.bmp\n" ); scanf( "%s", FileName); AddSlash( FileName );
PtPDF417DecodeRegister("12345678901234567890");//use the license key of demo version.
PtQRDecodeRegister ("12345678901234567890");//use the license key of demo version.
PtDMDecodeRegister ("12345678901234567890");//use the license key of demo version.
PTDECODEPARA DecodePara;
DecodePara.dwStartX = 0;
DecodePara.dwStartY = 0;
DecodePara.dwEndX = 0;
DecodePara.dwEndY = 0;//search the whole image.
DecodePara.dwMaxCount= 0;//search the all symbols in the image.
PTTOTALBARCODEINFO BarCodeInfo;
int ret=0; int type=0;
printf( "\nSelect the kind of barcode to be decoded\n1: PDF417\n2: QRCode\n3: DataMatrix\n" ); scanf( "%d", &type); switch(type) { case 1: PtPDF417DecodeInit( &BarCodeInfo ); ret=PtPDF417DecodeFromFile ( FileName, &DecodePara, &BarCodeInfo ); if( ret==PT_IMAGERW_FAIL ) printf("Fail to load the file. Please check the file name is right\n"); if( ret!= PT_PDF417DECODE_SUCCESS ) ret=0; break; case 2: PtQRDecodeInit( &BarCodeInfo ); ret=PtQRDecodeFromFile ( FileName, &DecodePara, &BarCodeInfo ); if( ret==PT_IMAGERW_FAIL ) printf("Fail to load the file. Please check the file name is right\n");
if( ret!= PT_QRDECODE_SUCCESS ) ret=0; break; case 3: PtDMDecodeInit( &BarCodeInfo ); ret=PtDMDecodeFromFile ( FileName, &DecodePara, &BarCodeInfo ); if( ret==PT_IMAGERW_FAIL ) printf("Fail to load the file. Please check the file name is right\n");
if( ret!= PT_DMDECODE_SUCCESS ) ret=0; break; default: printf("Invalid Input\n"); return 0; } if( ret==0 )
printf("An error occured while rocognition\n");
else ShowBarCodeInfo( &BarCodeInfo );
switch(type) { case 1: PtPDF417DecodeFree( &BarCodeInfo ); break; case 2: PtQRDecodeFree( &BarCodeInfo ); break; case 3: PtDMDecodeFree( &BarCodeInfo ); break; } return 1;}
void AddSlash( char* FileName ){ int len1,len2, i; char* pSearch=FileName; while(1) { pSearch=strchr(pSearch, '/' ); if( pSearch==NULL) break; len1=strlen( FileName ); len2=strlen( pSearch ); for( i=len1; i>=len1-len2; i--) FileName[i+1]=FileName[i]; pSearch = pSearch+2; }}void ShowBarCodeInfo( PTTOTALBARCODEINFO* pBar ){ int count, i;
char ch[200];
if( pBar->dwTotalCount<=0 )
{
printf("No barcodes were found\n");
return;
}
printf( "Find %d barcodes\n", pBar->dwTotalCount );
for( count=0; count<int(pBar->dwTotalCount); count++)
{
int i;
printf( "barcode %d:\n", count+1 );
for( i=0; i<int(pBar->pInfoList[count].dwDataLen); i++)
printf("%c", pBar->pInfoList[count].pData[i]);
printf("\n\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -