mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-16 15:58:11 +00:00
Add border to generated QR codes
This commit is contained in:
parent
ca7c0e0c55
commit
f17c407100
2 changed files with 15 additions and 6 deletions
|
@ -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 a new issue