let sharedCanvas = wx.getSharedCanvas();
let sharedContext = sharedCanvas.getContext('2d')
let canvas = wx.createCanvas();
canvas.width = sharedCanvas.width;
canvas.height = sharedCanvas.height;
wx.onMessage(data => {
sharedContext.drawImage(canvas, 0, 0);
});
以上代码会报错,请问微信小程序如何获取用户的年龄。同样会报错的还有wx.createImage返回的对象一样会报错,这个刚才看到论坛里有一样的问题,到现在仍然没解决。
如果不在wx.onMessage理调用,比如直接在代码段里调用是没问题的,只要是在wx.xxxx的回调里执行都会报错,希望尽快解决这个问题。
------------------------------------------------------------------------------------------------------------------------------------------
gameSubContextThirdScriptError
Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)';at onMessage callback function
TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
at CanvasRenderingContext2D.t.(anonymous function) (http://127.0.0.1:57565/game/__dev__/WAGame.js:12:17613)
at CanvasRenderingContext2D.e.(anonymous function) [as drawImage] (http://127.0.0.1:57565/game/__dev__/WAGame.js:12:18953)
at Function.
(http://127.0.0.1:57565/game/js/open/index.js:11:17)
at f. (http://127.0.0.1:57565/game/__subdev__/WAGameSubContext.js:4:26185)
at f.emit (http://127.0.0.1:57565/game/__subdev__/WAGameSubContext.js:4:453)
at http://127.0.0.1:57565/game/__subdev__/WAGameSubContext.js:4:8953
at Object.p [as subscribeHandler] (http://127.0.0.1:57565/game/__subdev__/WAGameSubContext.js:3:13572)
at http://127.0.0.1:57565/game/__dev__/WAGame.js:3:16001
at Array.forEach ()
at Object.S [as publish] (http://127.0.0.1:57565/game/__dev__/WAGame.js:3:15965)
本文来自微信小程序开发者论坛 -微信小程序工厂 http://www.xcxgc.com,转载请保留,开发微信小程序、定制微信小程序来微信小程序工厂网。
网友回复
晨**回复:
代码片段的链接好像有问题,麻烦再提供一下