第二次拍照截取页面无图片,微信版本(6.5.22)以前是好的,代码如下
wx.createCameraContext().takePhoto({
quality:‘high’,
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();
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=>{});
}
});
},
fail:res=>{
AjaxMsg(res).then(res=>{});
}
});
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=>{});
}
});
不知道这样能不能奏效
我是
ctx.drawImage(file,0,0,width,height);
setTimeout(() => {
ctx.draw();
setTimeout(() => {
wx.canvasToTempFilePath()
}, 300)
}, 1000)