需求是要把一串数字转化成条码,显示在界面上供打印机打印。
过程是使用zint库转化文本为rgb的buffer,然后把rgb转换成qt的QPixmap,在界面上显示,
如果是MFC的话,原理相通,有rgb数据显示都好办。
-
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);
作者:帅得不敢出门 c++哈哈堂:31843264
阅读(2676) | 评论(0) | 转发(0) |