qt tone zint text into the displayed barcode and

Copyright: original articles without consent, is prohibited reprint https://blog.csdn.net/zmlovelx/article/details/83989037

Demand is to make a series of numbers is converted into bar code, the printer interface display for reference.

Conversion process using zint library text rgb Buffer, and then converts the rgb into QPixmap qt, displayed on the screen,

If MFC is the case, the principle of similarities, there rgb data are easy to handle.

QPixmap Bitmap2Pixmap(unsigned char *bitmap, int width, int height)
{
    QImage img(bitmap, width, height, QImage::Format_RGB888);
    QPixmap ret;
    ret.convertFromImage(img);
    return ret;
}



    struct zint_symbol *m_symbol;
    m_symbol = ZBarcode_Create();
    if (m_symbol == NULL)
    {
        QMessageBox::warning(this, "test", "ZBarcode_Create create failed!");
        return;
    }
    else
    {
        m_symbol->symbology = BARCODE_CODE128;
        m_symbol->scale = 2;
    }

    ZBarcode_Encode_and_Buffer(m_symbol, (unsigned char *)inputStr.toLocal8Bit().data(), deviceId.size(), 0);
    QPixmap pixmap = Bitmap2Pixmap((unsigned char *)m_symbol->bitmap, m_symbol->bitmap_width, m_symbol->bitmap_height);
    ui->codeLabel->setPixmap(pixmap);
    ZBarcode_Delete(m_symbol);

Author: handsome too afraid to go c ++ Haha Church: 31,843,264

Guess you like

Origin blog.csdn.net/zmlovelx/article/details/83989037