【发布时间】:2020-12-17 04:00:32
【问题描述】:
我在尝试将 QR 码画布作为带背景的图像下载时遇到了麻烦。 下载工作正常,但由于边框不完整,我的设备无法扫描代码。我需要把后面的白色背景放大。
我当前的代码:
<a id="download-qr">
<div id="qrCode"></div>
$('#qrCode').qrcode({
render: "canvas",
minVersion: 8,
maxVersion: 8,
ecLevel: 'M',
size: 200,
mode: 0,
text: code,
});
var canvas = $("#qrCode").children(":first")[0];
var ctx = canvas.getContext("2d");
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
var img = canvas.toDataURL("image/jpeg");
var dl = document.getElementById('download-qr');
dl.setAttribute('href', img);
dl.setAttribute('download', 'test.jpg');
请帮助我。非常感谢。
【问题讨论】:
-
将您的
test (30).jpg添加到一些文件交换服务器。在我看来,该文件还可以,但是您的图像预览应用程序一直在添加黑色背景。 -
你使用的是什么api/库,需要在帖子中说明
标签: javascript html css canvas