qrcode只经过前端就能生成二维码和解析二维码图片,javascript
首先要引入文件qrcode.js,下载地址为:http://static.runoob.com/download/qrcodejs-04f46c6.zip;前端
一、识别本地图片:java
经过文件的形式获取到本地的图片,生成一个图片的临时路径,而后解析这个二维码图片;web
qrcode.decode(img)方法能将二维码图片解析,经过qrcode.callback=function(img){}将解析的图片返回文本值;chrome
//获取预览图片路径 var getObjectURL = function(file){ var url = null ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } return url ; } console.log(getObjectURL(newfile[0]));// newfile[0]是经过input file上传的二维码图片文件 qrcode.decode(getObjectURL(newfile[0])); qrcode.callback = function(imgMsg){ console.log("imgMsg",imgMsg); }
二、生成二维码:url
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 100,
height : 100
});firefox
qrcode.makeCode('123123');code
生成二维码blog