const ctx = uni.createCanvasContext(canvaId, this);
const fsm = wx.getFileSystemManager();
let extName = base64.match(/data\:\S+\/(\S+);/);
if (extName) {
extName = extName[1];
}
// const ctx = uni.createCanvasContext(canvaId, this);
let fileName = Date.now() + "." + extName;
let filePath = wx.env.USER_DATA_PATH + "/" + fileName;
fsm.writeFile({
filePath,
data: base64.replace(/^data:\S+\/\S+;base64,/, ""),
encoding: "base64",
success: (res) => {
wx.getImageInfo({
src: filePath,
success: (res) => {
console.log("Image info:", res, res.path);
ctx.drawImage(res.path, 0, 0, 300, 300); // 使用获取到的图片路径
ctx.draw(false, () => {
console.log("Canvas drawn");
}); // 绘制到画布
},
fail: (error) => {
console.error("获取图片信息失败:", error);
},
});
},
fail: (error) => {
console.error("写入失败", error);
},
});
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。