怎样生成二维码并显示?

这个是我用别人的js组件,写的demo项目。组件直接在空白UI上嵌入代码,还是蛮方便的。
demo项目地址
demo在线预览

2赞

这个H5和原生都可以用吗

mark~必须mark

maek

qrcode导入插件, new QRCode(-1, QRErrorCorrectLevel.H)报错,QRCode引用自哪里

3.3 导入报错


js这版用不了,不纠结了,花了一个小时转成ts了
qrcode.zip (12.4 KB)

5赞

先赞:+1: 后 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赞

真是个好哥哥

这个好哥哥的代码可以用 我3.5.1也能跑起来 放一个demo
firewood_qrcode_ts_3.x_.zip (63.1 KB)

1赞