自定义组件中canvas的canvasGetImageData获取不到数据

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

小程序代码:

wx.canvasGetImageData({

         canvasId: ‘PaperCanvas’,

         x: 0,

         y: 0,

         width: 100,

         height: 100,

         success:function(res) {

           console.log(res.width) // 100

           console.log(res.height) // 100

           console.log(res.data instanceof Uint8ClampedArray) // true

           console.log(res.data.length) // 100 * 100 * 4

           let pngData = upng.encode([res.data.buffer], res.width, res.height)

           let base64 = wx.arrayBufferToBase64(pngData)

         },

         fail: function (res) {

           console.log(res);

           return ‘’

         }

       }, this)

运行后报错:

errMsg:canvasGetImageData: fail canvas is empty

请帮忙解答,多谢各位!

7 回复
syuan
syuan1 楼6 年前

还没有解决

yongren
yongren2 楼6 年前

现在我也碰到了这个问题,请问解决了吗?

fangmao
fangmao3 楼6 年前

同遇到这个问题,解决了吗

azou
azou5 楼6 年前

解决了吗

xiulancai
xiulancai6 楼6 年前

还没解决

maming
maming7 楼5 年前

是不是你wxml没有canvas