请问为什么压缩出来的图片,在个别手机上是一张空白的图片了,代码如下
var Str_Image = function (that) {
var ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'low',
success: (res) => {
console.log(res);
var ctx = wx.createCanvasContext('photo_canvas');
var ratio = 2;
var canvasWidth = res.width
var canvasHeight = res.height;
while (canvasWidth > 200 || canvasHeight > 200) {
//比例取整
canvasWidth = Math.trunc(res.width / ratio)
canvasHeight = Math.trunc(res.height / ratio)
ratio++;
}
that.setData({
canvasWidth: canvasWidth,
canvasHeight: canvasHeight
}) //设置canvas尺寸
ctx.drawImage(res.tempImagePath, 0, 0, 150, 150) //canvasWidth, canvasHeight
ctx.draw()
//下载canvas图片
setTimeout(function () {
wx.canvasToTempFilePath({
canvasId: 'photo_canvas',
x: 0,
y: 0,
width: 150,
height: 150,
//生成图片的大小
destWidth: 150,
destHeight: 150,
success: function (res) {
that.setData({
imageUrl: res.tempFilePath,
});
uploadImage(that, res.tempFilePath, that.data.str_UserName) //that.data.str_UserName
},
fail: function (error) {
console.log(error)
}
})
}, 100)
},
fail: (res) => {
console.log(res);
}
})
}
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)