May 19, 2021 WeChat Mini Program Development Document
Base library 1.9.90 starts to support, and low versions need to be compatible
Method of creating a pattern for a specified image, you can repeat the meta-image in the specified direction
canvasContext.createPattern(image, repetition)
The property value | Type | Description |
---|---|---|
image | String | Repeated image sources, only in-package paths and temporary paths are supported |
repetition | String | Specify how to repeat the image, the valid values are: repeat, repeat-x, repeat-y, no-repeat |
const ctx = wx.createCanvasContext('myCanvas')
const pattern = ctx.createPattern('/path/to/image', 'repeat-x')
ctx.fillStyle = pattern
ctx.fillRect(0, 0, 300, 150)
ctx.draw()