Skip to main content

Context

new Konva.Context(config)

Konva 对原生 2d canvas context 的封装。它的 API 几乎与 2d context 相同,并增加了一些额外函数。使用 Konva 核心图形时,你不需要使用此对象。但如果你想创建自定义图形或自定义命中区域,则会使用它。有关每个 2d context API 的完整信息,请参阅 MDN 文档

自有方法​

fillShape(shape)​

填充图形

参数:

  • shape (Konva.Shape)

strokeShape(shape)​

描边图形

参数:

  • shape (Konva.Shape)

fillStrokeShape(shape)​

先填充再描边

参数:

  • shape (Konva.Shape)

reset()​

重置 canvas context 变换

getCanvas()​

获取 canvas 封装对象

返回: Konva.Canvas

clear(bounds)​

清除 canvas

参数:

  • bounds (Object)(可选)
  • bounds.x (Number)(可选)
  • bounds.y (Number)(可选)
  • bounds.width (Number)(可选)
  • bounds.height (Number)(可选)

arc()​

arc 函数。

arcTo()​

arcTo 函数。

beginPath()​

beginPath 函数。

bezierCurveTo()​

bezierCurveTo 函数。

clearRect()​

clearRect 函数。

closePath()​

closePath 函数。

createImageData()​

createImageData 函数。

createLinearGradient()​

createLinearGradient 函数。

createPattern()​

createPattern 函数。

createRadialGradient()​

createRadialGradient 函数。

drawImage()​

drawImage 函数。

ellipse()​

ellipse 函数。

isPointInPath()​

isPointInPath 函数。

fillRect()​

fillRect 函数。

strokeRect()​

strokeRect 函数。

fillText()​

fillText 函数。

measureText()​

measureText 函数。

getImageData()​

getImageData 函数。

lineTo()​

lineTo 函数。

moveTo()​

moveTo 函数。

rect()​

rect 函数。

roundRect()​

roundRect 函数。

putImageData()​

putImageData 函数。

quadraticCurveTo()​

quadraticCurveTo 函数。

restore()​

restore 函数。

rotate()​

rotate 函数。

save()​

save 函数。

scale()​

scale 函数。

setLineDash()​

setLineDash 函数。

getLineDash()​

getLineDash 函数。

setTransform()​

setTransform 函数。

stroke()​

stroke 函数。

strokeText()​

strokeText 函数。

transform()​

transform 函数。

translate()​

translate 函数。