感谢感谢,在ctx.drawImage之后加了延时问题就解决了
canvas 2d导出第一张图片时空白,是代码问题?用户上传的图片中第一张有可能是空白的图片,很奇怪,感觉是代码问题,ctx.drawImage后需要延迟调用canvasToTempFilePath吗? wx.createSelectorQuery() .select('#canvas') .fields({node: true, size: true}) .exec((res) => { const canvas = res[0].node let dpr = wx.getSystemInfoSync().pixelRatio; dpr = dpr > 2 ? 2 : dpr canvas.width = this.cWidth * dpr canvas.height = this.cHeight * dpr const ctx = canvas.getContext('2d') const img = canvas.createImage() img.src = tempFilePaths[0] img.onload = () => { ctx.drawImage(img, 0, 0, this.cWidth * dpr, this.cHeight * dpr) wx.canvasToTempFilePath({canvas, success: (res) => { ... }}) } })
2023-11-24