C语言 放大纸张上的QRCode显示



谁能帮我重写这段代码,使QRcode使用整个显示尺寸(200x200)?

我使用这个显示:
https://www.waveshare.com/1.54inch-e-paper-module.htm

下面是我用来创建QRCode的库:
https://github.com/ricmoo/qrcode/


点击查看图片

这是我的代码:

#include <SPI.h>
#include "epd1in54_V2.h"
#include "qrcode.h"
#include "epdpaint.h"
//set the pins of the ESP32
Epd epd(33, 25, 26, 27);        // my Pins ESP32 (Reset, DC, CS, Busy)
unsigned char image[1024];
Paint paint(image, 0, 0);
QRCode qrcode;
#define BLACK     0
#define WHITE   1
void setup()
{
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, 0, "https://vinotes.app");
epd.LDirInit();
epd.Clear();
paint.SetWidth(45);
paint.SetHeight(45);
paint.Clear(WHITE);
for (int y = 0; y < qrcode.size; y++) {
for (int x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
paint.DrawPixel(x, y, BLACK);
}
}
}
epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
epd.Sleep();
}
void loop()
{
}

不是迭代QR码的大小,而是迭代显示器的大小,并使用坐标除以比例因子请求QR模块。

在TouchGFX文档中有一个非常好的例子。(我知道你没有这样做,但同样的原则也适用。)

。如果你想把你的QR码放大4倍(伪码):

#define SCALE_FACTOR 4
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0, x < WIDTH; ++x)
{
setPixel(x, y, getModule(x / SCALE_FACTOR, y / SCALE_FACTOR));
}
}

你会想要找出最大的比例因子,将适合,并可能添加一些偏移来居中的图像。

编辑:要明确的是,不要迭代显示的文字宽度和高度,否则你不会得到一个方形QR码。两个循环的上界都是(qrcode)。size * SCALING_FACTOR).

最新更新