基础库 1.9.90 开始支持,低版本需做兼容处理
对指定的图像创建模式的方法,可在指定的方向上重复元图像
canvascontext.createpattern(image, repetition)
属性值 | 类型 | 说明 |
---|---|---|
image | string | 重复的图像源,仅支持包内路径和临时路径 |
repetition | string | 指定如何重复图像,有效值有: 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()