tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-04-10 18:18:34
Canvas
Last updated: 2025-04-10 18:18:34

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:
Value
Description
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.
Return value:RenderingContext. Drawing context.

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






Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon