首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用globalCompositeOperation "destination-out“之后,如何获得包含新形状的轮廓?

问在使用globalCompositeOperation "destination-out“之后,如何获得包含新形状的轮廓?
EN

Stack Overflow用户
提问于 2012-12-06 00:34:20
回答 2查看 2K关注 0票数 2

我有一个带有蓝色轮廓的圆弧,然后使用全局复合操作符"destination- out“覆盖了圆弧的一部分,导致部分圆弧被取消/切断,但这使得新形状的一部分没有轮廓,有什么简单的方法可以重新建立形状的轮廓吗?

可在此处找到工作示例:http://jsfiddle.net/NY2up/

​

​

代码语言:javascript
复制
var ctx = document.getElementById("display").getContext('2d');

ctx.beginPath();
ctx.arc(100, 100, 50, 0.0, 1.5, false);
ctx.lineTo(100, 100);
ctx.closePath();
ctx.fillStyle = 'red'
ctx.fill();
ctx.strokeStyle = 'blue';
ctx.lineWidth = 5;
ctx.stroke();

ctx.globalCompositeOperation = "destination-out";
ctx.beginPath();
ctx.arc(100, 100, 20, 0, Math.PI*2, true);
ctx.fill();
ctx.closePath();

​

EN

回答 2

Stack Overflow用户

发布于 2012-12-06 05:18:47

我所做的是将globalComposition重新设置为source-over,并在该点上划出一条部分弧线以获得效果。

代码语言:javascript
复制
ctx.beginPath();
ctx.arc(100, 100, 50, 0.0, 1.5, false);
ctx.lineTo(100, 100);
ctx.closePath();
ctx.fillStyle = 'red'
ctx.fill();
ctx.strokeStyle = 'blue';
ctx.lineWidth = 5;
ctx.stroke();


ctx.globalCompositeOperation = "destination-out";
ctx.beginPath();
ctx.arc(100, 100, 20, 0, Math.PI*2, true);
ctx.fill();
ctx.closePath();

// reset the global comp and draw a partial arc with the proper radians.
ctx.globalCompositeOperation = "source-over";
ctx.beginPath();
ctx.arc(100, 100, 20, 1.61,-0.11, true);
ctx.stroke();
ctx.closePath();
​
票数 1
EN

Stack Overflow用户

发布于 2012-12-06 01:19:52

我想你可以在画布上画第三个弧线

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13727928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档