mirror of https://github.com/status-im/qzxing.git
merging promag:2019-08-add-border-feature to support the optional drawing of white border around the generated qr code.
This commit is contained in:
commit
a5cb500a74
|
@ -206,8 +206,10 @@ Image{
|
|||
|
||||
Or use the encoding function with the optional custom settings that are passed like URL query parameters:
|
||||
|
||||
<<<<<<< HEAD
|
||||
| attribute name | value | description |
|
||||
| -------------- | ---------- | --------------------------------------------- |
|
||||
| --------------- | ---------- | --------------------------------------------- |
|
||||
| border | true, false | whether the image has a border |
|
||||
| correctionLevel | L, M, Q, H | the error correction level |
|
||||
| format | qrcode | the encode formatter. Currently only QR Code. |
|
||||
|
||||
|
|
|
@ -575,7 +575,8 @@ QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
|
|||
QImage QZXing::encodeData(const QString& data,
|
||||
const EncoderFormat encoderFormat,
|
||||
const QSize encoderImageSize,
|
||||
const EncodeErrorCorrectionLevel errorCorrectionLevel)
|
||||
const EncodeErrorCorrectionLevel errorCorrectionLevel,
|
||||
const bool border)
|
||||
{
|
||||
QImage image;
|
||||
|
||||
|
@ -595,12 +596,23 @@ QImage QZXing::encodeData(const QString& data,
|
|||
|
||||
Ref<qrcode::ByteMatrix> bytesRef = barcode->getMatrix();
|
||||
const std::vector< std::vector <zxing::byte> >& bytes = bytesRef->getArray();
|
||||
image = QImage(int(bytesRef->getWidth()), int(bytesRef->getHeight()), QImage::Format_ARGB32);
|
||||
for(size_t i=0; i<bytesRef->getWidth(); i++)
|
||||
for(size_t j=0; j<bytesRef->getHeight(); j++)
|
||||
image.setPixel(int(i), int(j), bytes[j][i] ?
|
||||
qRgb(0,0,0) :
|
||||
qRgb(255,255,255));
|
||||
const int width = int(bytesRef->getWidth()) + (border ? 2 : 0);
|
||||
const int height = int(bytesRef->getHeight()) + (border ? 2 : 0);
|
||||
const QRgb black = qRgb(0, 0, 0);
|
||||
const QRgb white = qRgb(255, 255, 255);
|
||||
|
||||
image = QImage(width, height, QImage::Format_ARGB32);
|
||||
image.fill(white);
|
||||
|
||||
for (size_t i=0; i<bytesRef->getWidth(); ++i) {
|
||||
for (size_t j=0; j<bytesRef->getHeight(); ++j) {
|
||||
if (bytes[j][i]) {
|
||||
int x = int(i) + (border ? 1 : 0);
|
||||
int y = int(j) + (border ? 1 : 0);
|
||||
image.setPixel(x, y, black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image = image.scaled(encoderImageSize);
|
||||
break;
|
||||
|
|
|
@ -182,7 +182,8 @@ public slots:
|
|||
static QImage encodeData(const QString& data,
|
||||
const EncoderFormat encoderFormat = EncoderFormat_QR_CODE,
|
||||
const QSize encoderImageSize = QSize(240, 240),
|
||||
const EncodeErrorCorrectionLevel errorCorrectionLevel = EncodeErrorCorrectionLevel_L);
|
||||
const EncodeErrorCorrectionLevel errorCorrectionLevel = EncodeErrorCorrectionLevel_L,
|
||||
const bool border = false);
|
||||
|
||||
/**
|
||||
* Get the prossecing time in millisecond of the last decode operation.
|
||||
|
|
|
@ -28,6 +28,7 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
|
|||
QString data;
|
||||
QZXing::EncoderFormat format = QZXing::EncoderFormat_QR_CODE;
|
||||
QZXing::EncodeErrorCorrectionLevel correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
|
||||
bool border = false;
|
||||
|
||||
int customSettingsIndex = id.lastIndexOf(QRegularExpression("\\?(correctionLevel|format)="));
|
||||
if(customSettingsIndex >= 0)
|
||||
|
@ -56,12 +57,16 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
|
|||
correctionLevel = QZXing::EncodeErrorCorrectionLevel_M;
|
||||
else if(correctionLevelString == "L")
|
||||
correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
|
||||
|
||||
if (optionQuery.hasQueryItem("border")) {
|
||||
border = optionQuery.queryItemValue("border") == "true";
|
||||
}
|
||||
} else
|
||||
{
|
||||
data = id.mid(slashIndex + 1);
|
||||
}
|
||||
|
||||
QImage result = QZXing::encodeData(data, format, requestedSize, correctionLevel);
|
||||
QImage result = QZXing::encodeData(data, format, requestedSize, correctionLevel, border);
|
||||
*size = result.size();
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue