Answer the question
In order to leave comments, you need to log in
How to redraw lines in HTML5?
Hey All!
I'm doing a mini graphic editor
when drawing lines, I ran into a problem , the
idea was to draw a line in the "XOR" mode and overwrite the previous one on the next drawing, so it turns out that I can drag the line behind the cursor without overwriting the image,
but when overwriting, it turned out that there was a "trace" from the old line, edges are not rubbed
here example:
jsfiddle.net/uv0gk2pn/8
who faced how to solve the problem?
PS
The variant with erasing through clearRect(...) is not suitable, since you will have to restore an already drawn picture, and this is an excess load
Answer the question
In order to leave comments, you need to log in
Make two canvas elements on top of each other. In the lower image, in the upper, "working", line is dragged. Then it can be erased with clearRect.
<div style="position: relative;">
<canvas id="layer1" width="100" height="100"
style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
<canvas id="layer2" width="100" height="100"
style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question