# CanvasGradient CanvasContext.createLinearGradient(number x0, number y0, number x1, number y1)
with Promise style call: Not supported
Mini Program plugin: Support
Creates a linear gradient color. ReturnedCanvasGradient
The object needs to use the CanvasGradient.addColorStop() To specify gradient points, you need at least two.
# parameter
# number x0
Starting point x coordinate
# number y0
Starting point and coordinate
# number x1
Terminal x coordinate
# number y1
Terminal and coordinate
# Return value
# CanvasGradient
# sample code
const ctx = wx.createCanvasContext('myCanvas')
// Create linear gradient
const grd = ctx.createLinearGradient(0, 0, 200, 0)
grd.addColorStop(0, 'red')
grd.addColorStop(1, 'white')
// Fill with gradient
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()
The translations are provided by WeChat Translation and are for reference only. In case of any inconsistency and discrepancy between the Chinese version and the English version, the Chinese version shall prevail.Incorrect translation. Tap to report.