canvasContext.createPattern

解释:对指定的图像创建模式的方法,可在指定的方向上重复元图像。

参数:

参数名类型说明
imageString重复的图像源,仅支持包内路径和临时路径 。
repetitionString指定如何重复图像,有效值有: repeat, repeat-x, repeat-y, no-repeat。

示例:

  1. 1

  1. canvasContext.createPattern(image, repetition);

示例:

  1. 1
    2
    3
    4
    5

  1. const ctx = swan.createCanvasContext('myCanvas');
    const pattern = ctx.createPattern('/path/to/image', 'repeat-x');
    ctx.fillStyle = pattern;
    ctx.fillRect(0, 0, 300, 150);
    ctx.draw();