Free_Drawing
title: Free Drawing Konva Demo layout: demo_page
There are many ways to implement free drawing tools in Konva.
I see two most common and simple ways:
- Konva-based vector graphics (simple)
- Manual drawing into 2d canvas (advanced)
Free drawing with Konva nodes
So the first and probably the simplest ways is:
- Start a new
Konva.Line
onmousedown
/touchstart
- Add new point into the line while
mousemove
/touchmove
That way works ok for many applications. Also it is simple to store the state of the drawing somewhere in vector representation (like React store or JSON saving into database).
Free drawing manually
The first approach has limitation if we want to use some low-level 2d canvas API directly. If you need advanced access to the canvas it is better to use Native Context Access
We will create special offscreen canvas where we will add all drawings.
With native access to the canvas we can use low-level 2d context functions.
To display the canvas on the stage we will use Konva.Image
.