微信小程序API 绘图createLinearGradient(创建线性渐变)

绘图接口和方法

canvasContext.createLinearGradient


定义

创建一个线性的渐变颜色。

Tip: 需要使用addColorStop()来指定渐变点,至少要两个。

参数

参数 类型 定义
x0 Number 起点的x坐标
y0 Number 起点的y坐标
x1 Number 终点的x坐标
y1 Number 终点的y坐标

例子

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()

绘图接口和方法

版权声明:本文由lzhuji.com主机评测所有
文章名称:《微信小程序API 绘图createLinearGradient(创建线性渐变)》
文章链接:https://www.lzhuji.com/271611.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

本站不对信息的真伪做任何的保障,请自行甄别,自负责任。

登录

找回密码

注册