大学生之家,大学生资讯发布平台
大学生之家

小程序画布画出当前路径的边框CanvasContext.stroke

    发布时间:2025-04-15    阅读:
    来源:大学生之家
CanvasContext.stroke()
画出当前路径的边框。默认颜色色为黑色。

小程序插件:支持
示例代码
const ctx = wx.createCanvasContext('myCanvas')
ctx.moveTo(10, 10)
ctx.lineTo(100, 10)
ctx.lineTo(100, 100)
ctx.stroke()
ctx.draw()


stroke() 描绘的的路径是从 beginPath() 开始计算,但是不会将 strokeRect() 包含进去。

const ctx = wx.createCanvasContext('myCanvas')
// begin path
ctx.rect(10, 10, 100, 30)
ctx.setStrokeStyle('yellow')
ctx.stroke()
 
// begin another path
ctx.beginPath()
ctx.rect(10, 40, 100, 30)
 
// only stoke this rect, not in current path
ctx.setStrokeStyle('blue')
ctx.strokeRect(10, 70, 100, 30)
 
ctx.rect(10, 100, 100, 30)
 
// it will stroke current path
ctx.setStrokeStyle('red')
ctx.stroke()
ctx.draw()
计算机学习推荐
  • 扫一扫 分享悦读 ➤
  • 扫码可以分享到微信 qq朋友圈
计算机学习热点