mirror of
https://github.com/monero-project/monero-gui
synced 2024-11-28 09:31:37 +01:00
Add border to generated QR codes
This commit is contained in:
parent
7adeb694c1
commit
79452bc9ac
@ -473,7 +473,7 @@ Rectangle {
|
||||
Image {
|
||||
id: qrCode
|
||||
anchors.fill: parent
|
||||
anchors.margins: 6
|
||||
anchors.margins: 1
|
||||
|
||||
smooth: false
|
||||
fillMode: Image.PreserveAspectFit
|
||||
|
@ -7,12 +7,21 @@ QImage QRCodeImageProvider::genQrImage(const QString &id, QSize *size)
|
||||
using namespace qrcodegen;
|
||||
|
||||
QrCode qrcode = QrCode::encodeText(id.toStdString().c_str(), QrCode::Ecc::MEDIUM);
|
||||
QImage img = QImage(qrcode.size, qrcode.size, QImage::Format_Mono);
|
||||
for (int y = 0; y < qrcode.size; ++y)
|
||||
for (int x = 0; x < qrcode.size; ++x)
|
||||
img.setPixel(x, y, !qrcode.getModule(x, y)); // 1 is black, not "255/white"
|
||||
unsigned int black = 0;
|
||||
unsigned int white = 1;
|
||||
unsigned int borderSize = 4;
|
||||
unsigned int imageSize = qrcode.size + (2 * borderSize);
|
||||
QImage img = QImage(imageSize, imageSize, QImage::Format_Mono);
|
||||
|
||||
for (unsigned int y = 0; y < imageSize; ++y)
|
||||
for (unsigned int x = 0; x < imageSize; ++x)
|
||||
if ((x < borderSize) || (x >= imageSize - borderSize) || (y < borderSize) || (y >= imageSize - borderSize))
|
||||
img.setPixel(x, y, white);
|
||||
else
|
||||
img.setPixel(x, y, qrcode.getModule(x - borderSize, y - borderSize) ? black : white);
|
||||
if (size)
|
||||
*size = QSize(qrcode.size, qrcode.size);
|
||||
*size = QSize(imageSize, imageSize);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user