2016-11-20 14:36:14 +02:00
|
|
|
#include "QrCode.hpp"
|
|
|
|
|
|
|
|
#include "QRCodeImageProvider.h"
|
|
|
|
|
|
|
|
QImage QRCodeImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
|
|
|
{
|
|
|
|
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)
|
2016-11-25 01:31:44 +02:00
|
|
|
img.setPixel(x, y, !qrcode.getModule(x, y)); // 1 is black, not "255/white"
|
2016-11-20 14:36:14 +02:00
|
|
|
if (size)
|
|
|
|
*size = QSize(qrcode.size, qrcode.size);
|
|
|
|
return img;
|
|
|
|
}
|