search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

純C/C++ QrCode 產生器 [CB_QrCode] – jashliao部落格

純C/C++ QrCode 產生器 [CB_QrCode]


GITHUB: https://github.com/jash-git/CB_QrCode.git


code

#include 
#include 
#include 
#include "BitmapImage.h"
#include "bssQRCodeGenerator.h"

using namespace std;


int main( int argc, char* argv[] )
{
    //
    // Check command line
    //
    if( argc != 3 )//if( argc != 3 || strcmp( argv[ 1 ], "?" ) == 0 )
    {
        cout << "Usage: BSSDemoAppCon  " << endl;
        return 0;
    }

    string Content  = argv[ argc - 2 ];
    string FileName = argv[ argc - 1 ];


    //
    // Start generation
    //

    int iHeight     = 0;
    int iWidth      = 0;
    int iRowStride  = 0;
    void* pvImage   = NULL;

    int nRes = BSS_GenerateQRCode( Content.c_str(),
                                   Content.length(),
                                   3,
                                   4,
                                   &pvImage,
                                   &iWidth,
                                   &iHeight,
                                   &iRowStride );

    //
    // Output results
    //

    if( nRes == BSSG_QRCODE_OK )
    {
        cout << "Barcode generation: SUCCESS" << endl;
    }
    else
    {
        cout << "Barcode generation: FAILURE" << endl;
    }

    switch( nRes )
    {
        case BSSG_QRCODE_ERR_GENERIC:
             cerr << endl << "Note: Generic error code. The library doesn̿ clarify or cannot determine what is happening." << endl;
             break;
        case BSSG_QRCODE_ERR_OUTOFMEMORY:
             cerr << endl << "Note: Ran out of memory. Some allocation failed." << endl;
             break;
        case BSSG_QRCODE_ERR_NOTSUPPORTED:
             cerr << endl << "Note: The feature requested is not supported." << endl;
             break;
        case BSSG_QRCODE_ERR_INVALIDARGS:
             cerr << endl << "Note: Argument validation failed." << endl;
             break;
        case BSSG_QRCODE_ERR_OUTOFSYMBOLOGY:
             cerr << endl << "Note: Cannot create the barcode symbol that would be contain this specified input data string by the reason of  some bar code symbology limitation (one or more characters from input data string do not belong  to symbology character set, input data string is too long, etc.)" << endl;
             break;
    }

    if( nRes != BSSG_QRCODE_OK )
        return 0;


    //
    // Save the barcode image into the file
    //
    unsigned char* pImage = static_cast( pvImage );

    CBitmapImage Image;
    Image.Attach( pImage, iWidth, iHeight, iRowStride );

    if( Image.Save8bppBitmap( FileName ) )
    {
        cerr << endl << "I/O Error: Unable to open the output file." << endl;
    }

    Image.Detach();


    //
    // Release allocated resources
    //

    BSS_ReleaseQRCodeImage( pvImage, iHeight, iWidth, iRowStride );

    return nRes;
}


熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦