wx.createCanvas
This API is called using wx.createCanvas().
Feature description:Creates a canvas object. The first call creates a canvas displayed on the screen, while subsequent calls create off-screen.
Return value:Canvas. A canvas object. Canvas
Property
number width: Width of the canvas.
number height: Height of the canvas.
Method
Canvas.getContext
This API is called using Canvas.getContext(string contextType, Object contextAttributes).
Feature description:Gets the drawing context for the canvas object.
Parameter and description:
string contextType. Context type. Valid values:
|
2d | 2D drawing context. |
webgl | WebGL drawing context. |
webgl2 | WebGL2 drawing context. |
Object contextAttributes. WebGL context property, and it is effective only when the contextType is WebGL.
Property | Type | Default value | Required | Description |
antialias | boolean | false | False | Whether to use anti-aliasing. |
preserveDrawingBuffer | boolean | false | False | Whether to preserve the drawing buffer after completing the drawing. |
antialiasSamples | number | 2 | False | The number of anti-aliased samples. The minimum value is 2, the maximum value cannot exceed the system limit. Supported on iOS only. |
Canvas.toDataURL
This API is called using Canvas.toDataURL().
Feature description:Returns the content drawn on the canvas as a data URI.
Return value: string.A data URI formatted string.
RenderingContext
Feature description:The drawing context for the canvas object.
Using Canvas.getContext('2d') returns a CanvasRenderingContext2D object, which implements most properties and methods defined in the HTML Canvas 2D Context . Using Canvas.getContext('webgl') returns a WebGLRenderingContext object, which implements all properties, methods, and constants defined in WebGL 1.0 . Using Canvas.getContext('webgl2') returns a WebGL2RenderingContext object, which implements all properties, methods, and constants defined in WebGL 2.0 . 2D APIs support
Unsupported 2D properties and methods on iOS/Android
globalCompositeOperation does not support the following values: source-in, source-out, destination-atop, lighter, copy. Using these values will not throw an error but will result in unexpected outcomes.
isPointInPath
isPointInStroke
setLineDash
getLineDash
lineDashOffset
shadowColor
shadowBlur
shadowOffsetX
shadowOffsetY
WebGL APIs support
Compressed textures support
The PVR format is supported on iOS
The ETC1 format is supported on Android