canvas生成二维码,并下载保存为本地的图片

时间:2022-11-17 06:36:15

function getTicket(id,salt){//qrcode生成canvas二维码
$(".zc-mask").show();
$(".edit-box").show();
var url = 'http://tour.s-linktimes.com/beta/payment.html?s='+salt+'&sid='+id;
//var fullUrl = 'http://tour.s-linktimes.com/travel/jsapi/auth?redirectUrl='+encodeURIComponent(url)+'&scope=snsapi_userinfo';
$('#qrcode').html('');
jQuery('#qrcode').qrcode({
render : "canvas",//也可以替换为table
width : 154,
height : 154,
correctLevel:0,
text : url,
});

}
$("#xz").on("click",function(){//exportCanvas,可将二维码转换为任意图片格式并保存到本地
var oCanvas = document.getElementsByTagName("canvas")[0];
oCanvas.setAttribute("id","myCanvas");
var exampleCanvasID = "myCanvas";
var exportCanvas = new ExportCanvas();
exportCanvas.loadConfigFile("static/js/canvasconfig.js");
exportCanvas.loadLanguageFile("static/js/canvasen.js");
exportCanvas.setMimeType("image/png");
exportCanvas.setExportQuality(1.0);
exportCanvas.export(exampleCanvasID,function(){
});

http://www.htmleaf.com/html5/html5-canvas/201505311942.html