GDI +中两个形状之间的空白空间

时间:2013-04-02 13:55:38

标签: c# gdi+

我正在尝试在GDI +(C#)中绘制自定义投影。我一直有这种尴尬的表情: Preview

我想我可以通过在弧的宽度上添加一个像素来解决它,但随后形状重叠。 Preview http://puu.sh/2sv2N

我完全不知道造成这一小块白色的原因。

这是我的代码:

Rectangle drawRect = new Rectangle(10, 10, 400, 400);
radius = 10;
// TOP //
Rectangle topRect = new Rectangle(drawRect.X + radius, drawRect.Y, drawRect.Width - 2 * radius, radius);
LinearGradientBrush topBrush = new LinearGradientBrush(new Rectangle(topRect.X, topRect.Y - 1, topRect.Width,topRect.Height + 2), firstColor, secondColor, 270f);
g.FillRectangle(topBrush, topRect);
topBrush.Dispose();

// LEFT //
Rectangle leftRect = new Rectangle(drawRect.X, drawRect.Y + radius, radius, drawRect.Height - 2 * radius);
LinearGradientBrush leftBrush = new LinearGradientBrush(new Rectangle(leftRect.X - 1, leftRect.Y, leftRect.Width + 2, leftRect.Height), firstColor, secondColor, 180f);
g.FillRectangle(leftBrush, leftRect);
leftBrush.Dispose();

// TOP LEFT //
GraphicsPath topLeftPath = new GraphicsPath();
topLeftPath.StartFigure();
topLeftPath.AddArc(new Rectangle(drawRect.X, drawRect.Y, 2 * radius, 2 * radius), 180, 90);
topLeftPath.AddLine(new Point(drawRect.X + radius, drawRect.Y), new Point(drawRect.X + radius, drawRect.Y + radius));
topLeftPath.AddLine(new Point(drawRect.X + radius, drawRect.Y + radius), new Point(drawRect.X, drawRect.Y + radius + 1));
topLeftPath.CloseFigure();
PathGradientBrush topLeftBrush = new PathGradientBrush(topLeftPath);
topLeftBrush.CenterPoint = new PointF(drawRect.X + radius, drawRect.Y + radius);
topLeftBrush.CenterColor = firstColor;
topLeftBrush.SurroundColors = new Color[] { secondColor };
g.FillPath(topLeftBrush, topLeftPath);
topLeftBrush.Dispose();
topLeftPath.Dispose();

提前致谢

1 个答案:

答案 0 :(得分:1)

感谢LarsTech,我得到了可行的解决方案。

e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;

这就完成了工作。

谢谢!