HTML canvas clip() method

Definition and Usage

clip() Methods cut any shape and size from the original canvas.

Tip:Once an area is cut, all subsequent drawings will be restricted to the cut area (cannot access other areas on the canvas). You can also save the current canvas area before using the clip() method by using the save() method and restore it at any time later (through the restore() method).

Example

From the canvas, cut a rectangle area of 200*120 pixels. Then, draw a green rectangle. Only the green rectangle part within the cut area is visible:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
// چسپ رینج کا قیام کریں
ctx.rect(50,20,200,120);
ctx.stroke();
ctx.clip();
// clip() کے بعد سبز مستطیل بناوا
ctx.fillStyle="green";
ctx.fillRect(0,0,150,100);

خود بخود کوشش کریں

زبان

context.clip();

براوزر کی دعومت

جداول میں نمبر، پہلی بار اس خاص کوالٹی کو پورا دینے والی براوزر کی نسلیں کے لئے دیئے گئے ہیں۔

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

تذکرہ:Internet Explorer 8 اور اس سے پچھلے نسلیں <canvas> عناصر کو نہیں دعومت دیتے ہیں۔