修复二维码大小显示问题 #11

This commit is contained in:
CPPAlien 2018-07-17 11:49:34 +08:00
parent b8ffc14965
commit 5c8d3b3c1a

View File

@ -759,18 +759,12 @@
console.warn('No canvas provided to draw QR code in!')
return;
}
//边框大小
const BORDER_SIZE = 0;
var size = Math.min(cavW, cavH);
str = that.utf16to8(str);//增加中文显示
var frame = that.getFrame(str),
var frame = that.getFrame(str);
// 组件中生成qrcode需要绑定this
px = Math.round(size / (width + BORDER_SIZE));
var roundedSize = px * (width + 8),
offset = Math.floor((size - roundedSize) / 2);
size = roundedSize;
//ctx.clearRect(0, 0, cavW, cavW);
var px = size / width;
if (bg) {
ctx.setFillStyle(bg)
ctx.fillRect(startX, startY, cavW, cavW);
@ -779,7 +773,7 @@
for (var i = 0; i < width; i++) {
for (var j = 0; j < width; j++) {
if (frame[j * width + i]) {
ctx.fillRect(startX + px * (4 + i) + offset, startY + px * (4 + j) + offset, px, px);
ctx.fillRect(startX + px * i, startY + px * j, px, px);
}
}
}