Here's one way to draw a cutout-polygon onto FabricJS:
AFAIK, FabricJS does not yet support the compositing necessary to create cutouts from its polygons, so here's a workaround.
Draw the cutout polygon onto an html5 canvas. For example
.globalCompositeOperation='destination-out'
. This will cause all new drawings to act as an "eraser" and will cut out any existing pixels under the new drawings. Use the html5 canvas as an image source for a new Fabric.Image
.
// Create your polygon with transparent cuts on this html5 canvas // Use destination-out compositing to "punch holes" in your polygon var html5canvas=document.getElementById('myhtml5CanvasElement'); // then use the html5 canvas as an image source for a new Fabric.Image var c=new Fabric.Image(html5Canvas);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.