wx.canvasToTempFilePath Android严重BUG
发布于 6 年前 作者 bsu 7462 次浏览 来自 问答

第二次拍照截取页面无图片,微信版本(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=>{});

           }

       });

10 回复

 setTimeout( () => {

                wx.canvasToTempFilePath()

}, 300)

我是300 , 用完全公司的安卓机都没出现问题

没用,各种问题

我的出现的问题麻烦帮忙看下  我的canvas预览图片的时候 在手机上只有代开调试 才能显示图片 关闭调试  图片不显示  怎么回事儿呢?

@嗯  我马上去试试,非常感谢您的帮助

@ 李帅领 你这问题无关紧要,因为是网络图片,就要打开调试,不过上线后就没事了

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)

               

非常感谢您的建议,已解决。但是还是有点纠结以前版本没有过

@嗯  首页很感谢您的回复,请教一下该如何写延迟?您上面写的我好像不能直接用,之前没用过延时的写法。下面是我的代码,请问如何正确写延时,希望能指教一下,非常感谢。

wx.canvasToTempFilePath({

canvasId: ‘identify’,

success: function success(res) {

var savedFilePath = res.savedFilePath;

    }

})

ctx.drawImage 存在 异步

建议 setTimeout  几百毫秒

药到病除?

官方说会给  ctx.drawImage加入回调 是在无法确定的下个版本

回到顶部