options.cameraContext.takePhoto({
quality: options.quality,
success: (photo) => {
wx.getImageInfo({
src: photo.tempImagePath,
success: function (res) {
var ctx = wx.createCanvasContext(options.canvasId, this);
var ratio = 1.1;
var canvasWidth = res.width;
var canvasHeight = res.height;
while (canvasWidth > options.sizeArea.maxWidth || canvasHeight > options.sizeArea.maxHeight) {
//比例取整
canvasWidth = Math.trunc(res.width / ratio)
canvasHeight = Math.trunc(res.height / ratio)
ratio = ratio + 0.1;
}
ratio = 1.1
while (canvasWidth < options.sizeArea.minWidth || canvasHeight < options.sizeArea.minHeight) {
//比例取整
canvasWidth = Math.trunc(canvasWidth * ratio)
canvasHeight = Math.trunc(canvasHeight * ratio)
ratio = ratio + 0.1;
}
var canvasData = {
canvasWidth: canvasWidth,
canvasHeight: canvasHeight
}
if (options.setData) {
options.setData(canvasData) //设置canvas尺寸
}
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(photo.tempImagePath, 0, 0, canvasWidth, canvasHeight);
ctx.draw()
//下载canvas图片
setTimeout(function () {
wx.canvasToTempFilePath({
canvasId: options.canvasId,
fileType: options.fileType,
destWidth: canvasWidth,
destHeight: canvasHeight,
success: function (res) {
if (options.success)
options.success(res);
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
},
fail: function (error) {
log.error("canvasToTempFilePath", error);
console.log('图片处理失败', error);
if (options.fail)
options.fail(error);
}
})
}, 600)
},
fail: function (error) {
log.error("getImageInfo", error);
console.log('获取图像失败', error);
if (options.fail)
options.fail(error);
}
})
},
fail: function (error) {
log.error("takePhoto", error);
console.log('摄像失败', error);
if (options.fail)
options.fail(error);
}
})
客户端版本:8.0.32 基础库版本:2.30.0 系统类型:Android
出现获取图像失败情况,错误信息:getImageInfo:fail parameter error: parameter.src should be String instead of Null;
有什么解决办法吗
