收藏
回答

wx.canvasToTempFilePath()真机导出失败?

wx.canvasToTempFilePath() 真机导出失败,模拟器正常。

fail invalid viewId


终端类型:微信iOS客户端

微信版本:8.0.40


代码片段如下:

let wxaCode = 'data:image/png;base64,xxx...';
let canvas = wx.createOffscreenCanvas({type: '2d', width: 500, height: 500});
let ctx = canvas.getContext('2d');

let image = canvas.createImage();
image.onload = function () {
    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
    wx.canvasToTempFilePath({
        canvas: canvas,
        fileType: 'jpg',
        success: console.log,
        fail: console.error
    })
}
image.src = wxaCode;
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容