真机上canvas使用wx.getImageInfo图片不显示

发布于 7 年前作者 li498273 次浏览最后编辑 7 年前来自 ask

用画布绘制一张图片,

图片从网络获取,然后用

wx.getImageInfo获取temp图片地址。

根据网上的说法,直接使用temp地址就能显示图片,但是我这控制台报错了,并且显示白板的图片。这是为什么?

var pictureSrc = https://XXXX/aaa.png” //图片能获取

var that = this

wx.getImageInfo({

    src: pictureSrc,

        success: function (res) {

            console.log(res.width)

            console.log(res.height)

            that.setData({

            temp1 : res.path

            })

    }

})

const ctx = wx.createCanvasContext(‘shareImg’)

ctx.drawImage(that.data.temp1, 0, 500, 150, 150)

//大图

1 回复
guping
guping1 楼5 年前

wx.getImageInfo是异步的,你这个temp1没数据呢