Skip to main content

Canvas

new Konva.Canvas(config)

Canvas Renderer constructor. It is a wrapper around native canvas element. Usually you don't need to use it manually.

Parameters

NameTypeDescription
configObject
widthNumber
heightNumber
pixelRatioNumber

Own Methods

getContext()

get canvas context

Returns: CanvasContext context

toDataURL(mimeType, quality)

to data url

Parameters:

  • mimeType (String)
  • quality (Number): between 0 and 1 for jpg mime types

Returns: String data url string

pixelRatio(pixelRatio)

get/set pixel ratio. KonvaJS automatically handles pixel ratio adustments in order to render crisp drawings on all devices. Most desktops, low end tablets, and low end phones, have device pixel ratios of 1. Some high end tablets and phones, like iPhones and iPads have a device pixel ratio of 2. Some Macbook Pros, and iMacs also have a device pixel ratio of 2. Some high end Android devices have pixel ratios of 2 or 3. Some browsers like Firefox allow you to configure the pixel ratio of the viewport. Unless otherwise specificed, the pixel ratio will be defaulted to the actual device pixel ratio. You can override the device pixel ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.

Parameters:

  • pixelRatio (Number)

Returns: Number

Example:

// get
var pixelRatio = layer.getCanvas.pixelRatio();

// set
layer.getCanvas().pixelRatio(3);