renderingcontext canvas.getcontext(string contexttype)
基础库 或更高版本; 若版本较低,建议采取 兼容处理。
主体: 企业支付宝小程序 、 个人支付宝小程序
返回 canvas 的绘图上下文。
string contexttype
绘图上下文类型。
枚举值 | 描述 | 兼容性 |
---|---|---|
2d | 2d 类型上下文。 | - |
webgl | webgl 类型上下文。 | - |
renderingcontext
代码示例
.js
.axml
page({
oncanvasready() {
my.createselectorquery().select('#canvas').node().exec((res) => {
const canvas = res[0].node
const ctx = canvas.getcontext('2d')
ctx.fillrect(10, 10, 100, 100)
})
}
})
<canvas id="canvas" type="2d" onready="oncanvasready">canvas>