安卓平台保存的图片
苹果14保存的图片
下面会少一段
let textCtx;
let textCanvas;
page({
ownTableQr() {
this.drowQrPic(bgcPath, picData, this.data.optNum.toString())
},
drowQrPic(bgcImagePath, qrImageData, tableNum) {
// 初始化画布大小
const dpr = wx.getWindowInfo().pixelRatio
textCanvas.width = 700 * dpr
textCanvas.height = 300 * dpr
textCtx.scale(dpr, dpr)
// textCtx.clearRect(0, 0, 1400, 600);
textCtx.beginPath();
const bg = textCanvas.createImage();
const qr = textCanvas.createImage();
//设置填充颜色 为白色
textCtx.fillStyle = "white";
//画矩形
textCtx.fillRect(0, 0, 700, 300)
textCtx.fillStyle = "black";
textCtx.font = "25px sans-serif";
bg.src = bgcImagePath;
qr.src = qrImageData;
bg.onload = () => {
textCtx.drawImage(qr, 42.5, 20, 200, 200)
textCtx.drawImage(bg, 0, 0, 700, 300)
textCtx.fillText(tableNum + '号台', 107.5, 285, 75);
}
},
async onQrConfirm() {
const res = await wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 700,
height: 300,
destWidth: 700,
destHeight: 300,
canvas: textCanvas,
})
console.log(res.tempFilePath)
const r = await wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath
})
console.log(r)
},
onReady() {
wx.createSelectorQuery().select('#myCanvas').fields({
node: true,
size: true
})
.exec((res) => {
textCanvas = res[0].node // 重点1
textCtx = textCanvas.getContext('2d') // 重点2
})
},
})