就像graphics.FillEllipse一样,但中间有个洞。我需要通过在它们周围放一个环来突出显示一些圆形图标,并且由于较大程序的限制,很难/不可能简单地在它们下面使用FillEllipse来使其看起来像是有一个洞。
发布于 2018-08-12 12:35:09
来自某物的答案中有一件很重要的事情,这是最灵活的答案,那就是需要处理GraphicsPath和Brush,因此将它们的声明放在using语句中,如下所示:
// Clear your Graphics object (defined externally)
gfx.Clear(Color.White);
// You need a path for the outer and inner circles
using (GraphicsPath path1 = new GraphicsPath(), path2 = new GraphicsPath())
{
// Define the paths (where X, Y, and D are chosen externally)
path1.AddEllipse((float)(X - D / 2), (float)(Y - D / 2), (float)D, (float)D);
path2.AddEllipse((float)(X - D / 4), (float)(Y - D / 4), (float)(D / 2), (float)(D / 2));
// Create a region from the Outer circle.
Region region = new Region(path1);
// Exclude the Inner circle from the region
region.Exclude(path2);
// Create a brush
using (SolidBrush b = new SolidBrush(Color.Blue))
{
// Draw the region to your Graphics object
gfx.FillRegion(b, region);
}
}这将确保在不再需要它们时将其丢弃。
使用是确保Dispose方法即使在发生异常时也会被调用的最佳方式。
https://stackoverflow.com/questions/1940080
复制相似问题