小程序畫布對指定的圖像創(chuàng)建模式的方法CanvasContext.createPattern
CanvasContext.createPattern(string image, string repetition)
對指定的圖像創(chuàng)建模式的方法,可在指定的方向上重復(fù)元圖像
基礎(chǔ)庫 1.9.90 開始支持,低版本需做兼容處理。
小程序插件:支持
參數(shù)
string image
重復(fù)的圖像源,支持代碼包路徑和本地臨時路徑 (本地路徑)
string repetition
如何重復(fù)圖像
repetition 的合法值
值 說明 最低版本
repeat 水平豎直方向都重復(fù)
repeat-x 水平方向重復(fù)
repeat-y 豎直方向重復(fù)
no-repeat 不重復(fù)
示例代碼
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()
作者:大學(xué)生新聞網(wǎng) 來源:大學(xué)生新聞網(wǎng)