Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API drawing createPattern


May 19, 2021 WeChat Mini Program Development Document


Table of contents


canvasContext.createPattern


Base library 1.9.90 starts to support, and low versions need to be compatible

Defined

Method of creating a pattern for a specified image, you can repeat the meta-image in the specified direction

Grammar

canvasContext.createPattern(image, repetition)

Parameters

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

Example

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()