Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the clip of a region in html 5 canvas

I am working with clip() in canvas.

I have made a region to clip(), as specified below

this.svgRenderer.ctx.rect(positionX, positionY, Width, Height);
this.svgRenderer.ctx.clip();

After few drawing on the same canvas, I am trying to remove the clip for that region by using save() and restore().

But I am making mistakes and can't get that. So suggest any other way to remove the clip for the specified region without using save() and restore()

like image 413
Jaya Avatar asked Aug 13 '14 09:08

Jaya


People also ask

How do you cut a canvas?

HTML canvas clip() Method Clip of a rectangular region of 200*120 pixels from the canvas. Then, draw a red rectangle. Only the part of the red rectangle that is inside the clipped area is visible: YourbrowserdoesnotsupporttheHTML5canvastag.

What is canvas area in HTML?

What is HTML Canvas? The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.


1 Answers

.clip is a permanent context state change.

It can only be removed by wrapping it in .save and .restore.

ctx.save();
ctx.clip(); // assuming the clipping path was already declared
// draw whatever needs to be clipped
ctx.restore(); // reset the clipping region
               // (and any other attributes that have been modified since .save())

Changing the canvas element width will clear the context state (and remove clipping) but will also erase the existing drawings.

like image 177
markE Avatar answered Oct 12 '22 07:10

markE