时间:2019-05-03 来源:小程序工厂
Y***:
我的canvasToTempFilePath也出问题了,也是安卓端,有时候有图片,有时候没有图片,但也不进入fail。
另外2台安卓机出现问题的机率又不一样,华为荣耀7出现没图片的机率少,中兴的没图片出现的机率很高。
之前都没出现这个问题的,希望能得到官方的回复,非常感谢
嗯***:
ctx.drawImage 存在 异步
建议 setTimeout 几百毫秒
药到病除?
官方说会给 ctx.drawImage加入回调 是在无法确定的下个版本
嗯***:
setTimeout( () => {
wx.canvasToTempFilePath()
}, 300)
我是300 , 用完全公司的安卓机都没出现问题
没用,各种问题
Y***:
@嗯 首页很感谢您的回复,请教一下该如何写延迟?您上面写的我好像不能直接用,之前没用过延时的写法。下面是我的代码,请问如何正确写延时,希望能指教一下,非常感谢。
wx.canvasToTempFilePath({
canvasId: 'identify',
success: function success(res) {
var savedFilePath = res.savedFilePath;
}
})
嗯***: success:res=>{ const width =this.data.canvasWidth; const height =this.data.canvasHeight; const unit=width/375; const file=res.tempImagePath; const ctx =wx.createCanvasContext('myCanvas'); ctx.drawImage(file,0,0,width,height); ctx.draw(); setTimeout( () => { wx.canvasToTempFilePath({ canvasId:'myCanvas', x:(width-75*unit)/2, y:50*unit, width:75*unit, height:450*unit, destWidth:75*unit, destHeight:450*unit, success:res=>{ const picture=res.tempFilePath; this.setData({rs:picture,takePhoto:false,focus:false}) }, fail:res=>{ AjaxMsg(res).then(res=>{}); } }); }, 300) }, fail:res=>{ AjaxMsg(res).then(res=>{}); } });
Y***:
@嗯 我马上去试试,非常感谢您的帮助
嗯***:
不知道这样能不能奏效
我是
ctx.drawImage(file,0,0,width,height);setTimeout(() => { ctx.draw(); setTimeout(() => { wx.canvasToTempFilePath() }, 300)
}, 1000)
M***:
非常感谢您的建议,已解决。但是还是有点纠结以前版本没有过
M***:系统记录
Y***:
目前完美解决,非常感谢您,希望更多有这个问题的朋友能看到