forked from PuddingPengChen/Qt-EncodeAndDecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcQrencode.cpp
More file actions
35 lines (33 loc) · 978 Bytes
/
tcQrencode.cpp
File metadata and controls
35 lines (33 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tcQrencode.h"
#include "./qrencode/qrencode.h"
#include <QPainter>
QImage TcQrencode::encodeImage(const QString& s, int bulk)
{
QImage ret;
QRcode* qr = QRcode_encodeString(s.toUtf8(), 1, QR_ECLEVEL_Q, QR_MODE_8, 0);
if ( qr != nullptr )
{
int allBulk = (qr->width) * bulk;
ret = QImage(allBulk, allBulk, QImage::Format_Mono);
QPainter painter(&ret);
QColor fg("black");
QColor bg("white");
painter.setBrush(bg);
painter.setPen(Qt::NoPen);
painter.drawRect(0, 0, allBulk, allBulk);
painter.setBrush(fg);
for( int y=0; y<qr->width; y++ )
{
for( int x=0; x<qr->width; x++ )
{
if ( qr->data[y*qr->width+x] & 1 )
{
QRectF r(x*bulk, y*bulk, bulk, bulk);
painter.drawRects(&r, 1);
}
}
}
QRcode_free(qr);
}
return ret;
}