收藏
回答

ios中接入canvas绘图空白?

使用canvas 新版 api

ios拍照后,创建image对象,img = canvas.createImage,src赋值失败,一直为空,导致画布一直空白。

在开发者工具与android 是正常的。唯独ios不行,也没有报错信息。

走的是img.onload,回调参数 undefined。

const img = cvs.createImage();
img.src = res.path;
// img.src
img.onload = async function () {
    // 画布渲染image
    ctx.drawImage(img, 0, 0, res.width, res.height, 0, 0, res.width, res.height);
    ctx.font = `${res.width / 30}px sans-serif`;
    ctx.fillStyle = 'blue';
    ctx.fillText(curTime, 20, res.height - 60);
    ctx.fillText(locationRes[0].name, 20, res.height - 40);
    uni.canvasToTempFilePath(
        {
            canvas: cvs,
            width: res.width,
            height: res.height,
            success: async (res) => {
                await uploadFile(e.tempFiles[i], res);
            },
            fail: (res) => {
                console.log('=====fail', res);
            }
        },
        getCurrentInstance()
    );
};

onReady(async () => {
    const query = uni.createSelectorQuery().in(getCurrentInstance());
    await query
        .select('#myCanvas')
        .fields({ size: true, node: true })
        .exec((res) => {
            cvs = res[0].node;
            ctx = res[0].node.getContext('2d');
        });
});


回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容