RenderingContextOffscreenCanvas.getContext(string contextType)

基础库 2.7.0 开始支持,低版本需做兼容处理。

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.16.1

相关文档: 画布指南、canvas 组件介绍

功能描述

这个方法会返回 OffscreenCanvas 的绘图上下文

参数

string contextType

绘图上下文的类型,需要和调用 createOffscreenCanvas 时传入的 type 保持一致

contextType 可以填的值

值 说明 最低版本
webgl webgl 类型的上下文
2d 2d 类型的上下文 2.16.1

返回值

RenderingContext

注意:webgl 和 2d 这两种绘图上下文不能混着用,传入的 contextType 必须和 wx.createOffscreenCanvas 传入的 type 类型一致。