wx.canvasToTempFilePath在调试基础库高于3.6为什么会无法获取到成功回调?画布是成功绘制了,但是调用wx.canvasToTempFilePath却一直提示:‘canvasToTempFilePath:fail fail canvas is empty’,但是在调试基础库改成3.4又能正常拿到成功的回调
var ctx = wx.createCanvasContext('firstCanvas');
ctx.clearRect(0, 0, canvasWidth, canvasWidth);
ctx.drawImage(filePath, 0, 0, canvasWidth, canvasWidth);
// ctx.draw();
self.cw = canvasWidth;
self.ch = canvasWidth;
ctx.draw(false, () => {
console.log("绘制成功了丫丫===")
// setTimeout(function() {
wx.canvasToTempFilePath({
canvasId: 'firstCanvas',
width: canvasWidth,
height: canvasWidth,
destWidth: canvasWidth,
destHeight: canvasHeight,
quality: quality,
success: (res) => {
console.log("比例",res)
// console.log("targetWidth===",targetWidth)
// console.log("targetHeight===",targetHeight)
// getImageInfo({
// src:res.tempFilePath,
// success(res1){
// console.log("压缩后===",res1)
// }})
//写入图片数组
setFilePath = res.tempFilePath;
self.$emit("upLoadFile", setFilePath,function(res:any){
if(!res){
showToast({title: "第"+number+"张图片上传失败!", duration: 1000})
}
self.recursionUploadImage(tempFilePaths,tempFileFile,(number+1),status);
// ctx.draw();//清空画布
// hideLoading();
});
},
fail: (err) => {
console.error(err)
}
}, self)
// }, 500);

这个接口停止维护了
通过wx.createSelectorQuery()直接获取画布对象实例 ,然后wx.canvasToTempFilePath 传入传入 canvas 组件实例
参考代码:https://developers.weixin.qq.com/s/eFk5Xamc7uW0