const ctx = wx.createCanvasContext('myCanvas')
ctx.drawImage(res.tempImagePath, 0, 0, 512, 512)
ctx.draw()
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 512,
height: 512,
canvasId: 'myCanvas',
success(res) {
wx.getFileSystemManager().readFile({
filePath: res.tempFilePath,
encoding: 'base64',
success: res => {
},
fail: res => {
console.log(res)
}
})
}
})
发现苹果跟安卓绘制出来的图片px大小并不统一512px, 哪里写错了吗?
参数要加上destWidth和destHeight这两个控制生成的图片宽高的属性就可以了