这个是我用别人的js组件,写的demo项目。组件直接在空白UI上嵌入代码,还是蛮方便的。
demo项目地址
demo在线预览
2赞
这个H5和原生都可以用吗
mark~必须mark
maek
qrcode导入插件, new QRCode(-1, QRErrorCorrectLevel.H)报错,QRCode引用自哪里
先赞
后 mark ,顺便 拍个马屁 大佬NB
Hi, how to use please!
let node = this.views["qr_code_node"]
var qrcode = new QRCode(-1, QRErrorCorrectLevel.H);
qrcode.addData('http://www.baidu.com');
qrcode.make();
var ctx = node.getComponent(Graphics)!;
ctx.fillColor = Color.BLACK;
var tileW = node.getComponent(UITransform)!.width / qrcode.getModuleCount();
var tileH = node.getComponent(UITransform)!.height / qrcode.getModuleCount();
// draw in the Graphics
for (var row = 0; row < qrcode.getModuleCount(); row++) {
for (var col = 0; col < qrcode.getModuleCount(); col++) {
if (qrcode.isDark(row, col)) {
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW));
ctx.rect(Math.round(col * tileW), Math.round(row * tileH), w, h);
ctx.fill();
} else {
// ctx.fillColor = cc.Color.WHITE;
}
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
}
}
}
1赞
真是个好哥哥
