1***@qq.com
1***@qq.com
  • 发布:2023-05-31 14:01
  • 更新:2023-08-28 09:45
  • 阅读:548

uni.canvasToTempFilePath 部分图片绘制不完全

分类:uni-app
compressImage(index) {  
    let that = this  
    let item = this.files[index]  
    uni.getImageInfo({  
        src: item.path,  
        success(res) {  
            var ratio = 2;  
            var canvasWidth = res.width  
            var canvasHeight = res.height  
            while (canvasWidth > 1024 || canvasHeight > 1024) {   
                canvasWidth = Math.trunc(res.width / ratio)  
                canvasHeight = Math.trunc(res.height / ratio)  
                ratio++;  
            }  
            that.cWidth = canvasWidth  
            that.cHeight = canvasHeight  
            var ctx = uni.createCanvasContext('canvas')  
            console.log(0.3 * (res.width + res.height))  
            ctx.drawImage(res.path, 0, 0, canvasWidth, canvasHeight)  
            ctx.draw(false, () => {  
                setTimeout(() => {  
                    uni.canvasToTempFilePath({  
                        canvasId: 'canvas',  
                        fileType: 'jpg',  
                        quality: 0.4,  
                        success: function(res1) {  
                            that.imgs.push(res1.tempFilePath)  
                            if (index < that.files.length - 1) that.compressImage(  
                                index + 1)  
                            else uni.hideLoading()  
                        },  
                        fail: function(res) {  
                            that.compressImage(index)  
                        },  
                        complete: function(res) {}  
                    })  
                }, 0.3 * (res.width + res.height))  
            })  
        },  
        fail(err) {  
            that.compressImage(index)  
        }  
    })  
}

已根据压缩前图片长款设定延迟执行时间 偶尔会出现图片绘制不全部分空白的情况发生 H5及模拟器皆会出现该问题 蹲一个解答

2023-05-31 14:01 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

我也遇到这个问题了,H5上面会有这个问题,小程序是正常的,第一次会截取一点图片别的空白,第二次点击获取图片就正常了

要回复问题请先登录注册