在微信小程序中調(diào)用scale方法對(duì)橫縱坐標(biāo)進(jìn)行縮放

2022-05-09 16:48 更新

微信小程序 canvas接口和方法繪圖接口和方法

canvasContext.scale


定義

在調(diào)用scale方法后,之后創(chuàng)建的路徑其橫縱坐標(biāo)會(huì)被縮放。多次調(diào)用scale,倍數(shù)會(huì)相乘。

參數(shù)

參數(shù)類(lèi)型說(shuō)明
scaleWidthNumber橫坐標(biāo)縮放的倍數(shù) (1 = 100%,0.5 = 50%,2 = 200%)
scaleHeightNumber縱坐標(biāo)軸縮放的倍數(shù) (1 = 100%,0.5 = 50%,2 = 200%)

例子

const ctx = wx.createCanvasContext('myCanvas')

ctx.strokeRect(10, 10, 25, 15)
ctx.scale(2, 2)
ctx.strokeRect(10, 10, 25, 15)
ctx.scale(2, 2)
ctx.strokeRect(10, 10, 25, 15)

ctx.draw()


微信小程序 canvas接口和方法繪圖接口和方法

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)