注意位置大小调整
链接来源:https://blog.youkuaiyun.com/tswc_byy/article/details/94594208
var qrcode =jQuery('#qrCodeOneCreate').qrcode({
width:250,
height:250,
render:"canvas", //设置渲染方式 table canvas
typeNumber : -1, //计算模式
correctLevel : 0,//纠错等级
background : "#ffffff",//背景颜色
foreground : "black",//前景颜色
text:qrCodeURL+row.qrId
});
var canvas = qrcode.find('canvas').get(0);
var img = new Image();
img.src = canvas.toDataURL('image/jpeg');
img.onload = function() {
canvas.width = 250;
canvas.height = 280;
var ctx = canvas.getContext('2d');
//设置画布背景
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
//设置文字样式
ctx.fillStyle = '#000000';
ctx.font = 'bold ' + 15 + 'px Arial';
ctx.textAlign = 'center';
//文字描述
ctx.fillText("测试", 125, 270);
//绘制二维码
ctx.drawImage(img, 0, 0);
}
width:250,
height:250, 是二维码宽和高
canvas.width = 250;
canvas.height = 280; 是canvas的宽和高 canvas.height 不height:250 高出30 这个30 就是为了展示文字高出的,
ctx.fillText("测试", 125, 270); 是文字的位置,
125 是250一半 也就是中间,270 比 height:250 多出20 这个20就是文字在原来的二维码最底下20.