系统绘制反转区域超出路径构建 [英] System Drawing Invert Region build out of Path
本文介绍了系统绘制反转区域超出路径构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个面板
,我在那个面板
上画了一颗心。.
但是我没有想画心我想画除了心的所有东西,所以心是透明的。
我可以反转从 Path
路径中选择的 Region
吗?
Ive got a panel
and im drawing a heart on that panel
..
But i dont want to draw the heart i want to draw everything except the heart so the heart is transparent.
Can i invert the Region
selected out of the Path
?
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
this.Region = new Region(path);
this.BackColor = Color.Black;
看起来像什么(白色=透明):
What it looks like(white = transparent):
我希望它看起来像什么(白色=透明):
What i want it to look like(white = transparent):
推荐答案
我认为您可以将两个图形路径加在一起。
I think you can just add 2 graphics paths together.
您可以尝试以下代码:
private void panel1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
GraphicsPath path2 = new GraphicsPath();
path2.AddRectangle(new Rectangle(new Point(0, 0), panel1.Size));
path2.AddPath(path, false);
e.Graphics.FillPath(Brushes.Black, path2);
}
结果是:
>
这篇关于系统绘制反转区域超出路径构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文