wx.canvasToTempFilePath({
canvasId: "myCanvas",
x: 0,
y: 0,
width: parseInt(imgInfo.width ),
height: parseInt(imgInfo.height),
destWidth: parseInt(imgInfo.width / 2),
destHeight: parseInt(imgInfo.height / 2),
success(res) {
console.log(res);
self.setData({ compressImageUrl: res.tempFilePath })
uploadFileOss(
res.tempFilePath,
function (fileUrl) {
console.log('uploadFile', fileUrl)
self.setData({ compressImageUrl: fileUrl })
},
function (err) {
console.log('err', err)
})
},
fail(info) {
console.log('myCanvas');
console.log(info);
}
})
实际导出来图片效果如下 黑色部分是透明的
把这几个设为一样大小:
width: parseInt(imgInfo.width ),
height: parseInt(imgInfo.height),
destWidth: parseInt(imgInfo.width / 2),
destHeight: parseInt(imgInfo.height / 2),