I assume the '\xCC' and '\xCE' characters are a start and end marker. Your array index 10 is mistyped, and I have converted it to a QByteArray. This code:
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
// QPrinter printer;
// printer.setOutputFormat(QPrinter::PdfFormat);
// printer.setOutputFileName("test.pdf");
image.fill(1);
painter.begin(&image);
barcodefont.
setLetterSpacing(QFont::AbsoluteSpacing,
10.0);
//deliberately spread out painter.setFont(barcodefont);
qDebug() << mytext;
painter.drawText(10, 90, mytext);
painter.end();
image.save("test.png");
return app.exec();
}
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// QPrinter printer;
// printer.setOutputFormat(QPrinter::PdfFormat);
// printer.setOutputFileName("test.pdf");
QImage image(640, 100, QImage::Format_Mono);
image.fill(1);
QPainter painter;
painter.begin(&image);
QFont barcodefont = QFont("code128", 32, QFont::Normal);
barcodefont.setLetterSpacing(QFont::AbsoluteSpacing,10.0); //deliberately spread out
painter.setFont(barcodefont);
QByteArray mytext("\xccMHB-6TG-6TG-GGHJ\xce");
qDebug() << mytext;
painter.drawText(10, 90, mytext);
painter.end();
image.save("test.png");
return app.exec();
}
To copy to clipboard, switch view to plain text mode
produces this output (this is the PNG, but the PDF looks the same):
test.png
The characters look good here.
Bookmarks