开放工具正常使用,真机测试就报错,尝试改了几次图片地址:本地临时链接、远程网络链接、base64都报错,图片不超过1M,分辨率600*600.
设备相关信息: SDKVersion: "3.4.2"
appId: undefined
appLanguage: "zh-Hans"
appName: undefined
appVersion: undefined
appVersionCode: undefined
enableDebug: false
fontSizeScaleFactor: 1
fontSizeSetting: 16
host: {env: "WeChat"}
hostLanguage: "zh-CN"
hostName: "WeChat"
hostSDKVersion: "3.4.2"
hostTheme: undefined
hostVersion: "8.0.5"
language: "zh_CN"
mode: "default"
version: "8.0.5"
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
/**
* 将图片路径转换为有效的图片对象
* @param {string} imagePath - 图片路径(包内图片路径、临时文件路径或网络图片路径)
* @returns {Promise<Object>} - 返回一个图片对象
*/
export function getImageObject(imagePath, canvasInstance) {
return new Promise(async (resolve, reject) => {
try {
if (imagePath.startsWith('cloud')) {
const getRes = await wx.cloud.getTempFileURL({
fileList: [{
fileID: imagePath,
maxAge: 60 * 60, // one hour
}]
})
imagePath = getRes.fileList[0].tempFileURL
console.log("网络路径",imagePath)
// wx.getImageInfo()
const imageInfo = await uni.getImageInfo({
src: imagePath
})
imagePath = imageInfo.path;
/* const downRes = await wx.cloud.downloadFile({
fileID: imagePath
})
imagePath = downRes.tempFilePath; */
}
const coverImg = canvasInstance.createImage();
console.log("加载元素",imagePath)
coverImg.onload = (e) => {
console.log(e, "图片元素", coverImg)
resolve(e.path[0])
}
coverImg.src = imagePath;
} catch (e) {
//TODO handle the exception
console.log(e, "图片元素加载失败")
uni.hideLoading()
reject(e)
}
})
}
您好,请问这个问题你解决了吗?