刘统建
刘统建
  • 发布:2020-12-15 16:37
  • 更新:2024-08-12 10:44
  • 阅读:2705

uni.canvasToTempFilePath在微信小程序中的坑

分类:uni-app

我要做的功能是在微信小程序上使用人脸识别接口然后获取人物的整个头部,这个时候用到了uni.canvasToTempFilePath。
直接上代码吧。

this.context.fillStyle = '#ffffff';  
this.context.fillRect(0, 0, image.width, image.height);  
this.context.draw(true,()=>{  
    this.context.drawImage(path, 0, 0, image.width, image.height)  
    this.context.draw(true,()=>{  
        uni.canvasToTempFilePath({  
            x: this.rect.x,  
            y: this.rect.y,  
            width: this.rect.width,  
            height: this.rect.height,  
            destWidth: this.rect.width,  
            destHeight: this.rect.height,  
            canvasId: 'myCanvas',  
            success: function(res) {  
                // 在H5平台下,tempFilePath 为 base64  
                console.log(res)  
                _this.url = res.tempFilePath;  
                }  
          })  
    })  
})
0 关注 分享

要回复文章请先登录注册

2***@qq.com

2***@qq.com

然后呢
2024-08-12 10:44