CanvasContext.stroke()

画出当前路径的边框。默认颜色色为黑色。

示例代码

  1. const ctx = wx.createCanvasContext('myCanvas')
  2. ctx.moveTo(10, 10)
  3. ctx.lineTo(100, 10)
  4. ctx.lineTo(100, 100)
  5. ctx.stroke()
  6. ctx.draw()

CanvasContext.stroke - 图1

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

  1. const ctx = wx.createCanvasContext('myCanvas')
  2. // begin path
  3. ctx.rect(10, 10, 100, 30)
  4. ctx.setStrokeStyle('yellow')
  5. ctx.stroke()
  6. // begin another path
  7. ctx.beginPath()
  8. ctx.rect(10, 40, 100, 30)
  9. // only stoke this rect, not in current path
  10. ctx.setStrokeStyle('blue')
  11. ctx.strokeRect(10, 70, 100, 30)
  12. ctx.rect(10, 100, 100, 30)
  13. // it will stroke current path
  14. ctx.setStrokeStyle('red')
  15. ctx.stroke()
  16. ctx.draw()

CanvasContext.stroke - 图2