[英]How do I fill a rectangle with the exception of a area
I am trying to fill a rectangle in a winforms application less a ellipse in the center that allows the image in the background to show through. 我正在尝试在winforms应用程序中填充一个矩形,而不是在中心放置一个椭圆形,以使背景中的图像能够显示出来。
can anyone give me a hint on which way to go on this, 谁能给我一个提示,指出进行此操作的方式,
thanks. 谢谢。
this is what I have come up with so far: 到目前为止,这是我想出的:
path.AddRectangle(new Rectangle(30, 30, 100, 100));
path.AddEllipse(new Rectangle(50, 50, 60, 60));
gfx.FillPath(new SolidBrush(Color.Black), path);
protected override void OnPaint(PaintEventArgs e){
var rgn = new Region(new Rectangle(50, 50, 200, 100));
var path = new GraphicsPath();
path.AddEllipse(60, 60, 180, 80);
rgn.Exclude(path);
e.Graphics.FillRegion(Brushes.Blue, rgn);
}
The easy way: 简单的方法:
It isn't clear enough what kind of transparency is required there. 尚不清楚那里需要什么样的透明度。 The simple way is to invert the problem.
简单的方法是解决问题。 Use a TextureBrush to draw the image with Graphics.FillEllipse().
使用TextureBrush通过Graphics.FillEllipse()绘制图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.