c# - C# 区域平滑问题。路径是平滑的,直到区域设置为路径
问题描述
我附上平滑版本的 ss,然后是丑陋的版本。每当我将区域设置为圆角矩形时,我的表单的背面颜色就会显示在路径像素的后面,从而使平滑的外观变得难看。我怎样才能更好地做到这一点?
尝试制作平滑的圆形形式!
我用来绘制矩形的代码
SolidBrush sb = new SolidBrush(Color.Black);
Size s = new Size(10, 10);
Rectangle r = new Rectangle(new Point(0, 0), s);
r.Width = this.Width;
r.Height = this.Height;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
SetNewRegion.FillRoundedRectangle(e.Graphics, sb, r, 25);
SetNewRegion 文件函数。
public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
{
if (graphics == null)
throw new ArgumentNullException("graphics");
if (brush == null)
throw new ArgumentNullException("brush");
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
{
graphics.FillPath(brush, path);
}
}
public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
{
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
Rectangle arc = new Rectangle(bounds.Location, size);
GraphicsPath path = new GraphicsPath();
if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}
path.AddArc(arc, 180, 90);
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = bounds.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
最后,通过使用 FillRoundedRectangle 的更改版本来简单地添加区域,使我能够使用相同的路径但以区域形式构建区域。
this.Region = SetNewRegion.WindowBounds(e.Graphics, sb, r, 25);
解决方案
推荐阅读
- java - Spring - 2 个应用程序可以同时使用相同的 @Transactional 服务吗?
- gradient - Pytorch 二阶导数卡在两个错误之间:缓冲区已释放且变量易失
- javascript - 自动跳过不属于 TypeScript 类型的属性
- python - Django Coverage ModuleNotFoundError:没有名为“django_extensions”的模块
- cross-platform - 初学者交叉编译 mipsel
- excel - Excel VBA:打开工作簿时类型不匹配?
- reactjs - 按垂直顺序排列元素
- java - 在数组列表中搜索 [JAVA]
- c# - Microsoft Dynamics 365 组织名称异常
- c# - 具有任何对象类型的名称和集合的 C# 类