GDI+:如何填充三角形?

发布于 2024-10-12 23:21:18 字数 1250 浏览 5 评论 0原文

我想用 LinearGradient 填充矩形(即三角形)的左下半部分:

alt text

从颜色改为透明: alt text

填充半个矩形:

alt text

我知道点 (x,y) 和矩形的大小。

如果我尝试使用 LinearGradientBrush,执行我的线性渐变:

brush = new LinearGradientBrush(
      MakePoint(0, y), //bottom left corner
      MakePoint(x, 0), //upper right corner
      MakeColor(255, c), //fully opaque color
      MakeColor(0, c)); //fully transparent color
graphics.FillRectangle(brush, MakeRect(0, 0, w, h));

线性渐变画笔填充整个矩形,如果它继续用最终(透明)颜色填充矩形的其余部分,那就太好了;但它却环绕着:

alt text

我有我喜欢的 LinearGradientBrush ,我只是想要到 FillTriangleFillPolygon,而不是 FillRectangle。除了没有 FillTriangle 或 FillPolygon,只有 FillRectangle 和 FillEllipse 之外。

另请参阅

链接文本

i want to fill the bottom-left half of a a rectangle (i.e. a triangle):

alt text

with a LinearGradient, going from color to transparent:
alt text

Filling half a rectangle:

alt text

i know the point (x,y), and the size of the rectangle.

If i try using a LinearGradientBrush, to perform my linear gradient:

brush = new LinearGradientBrush(
      MakePoint(0, y), //bottom left corner
      MakePoint(x, 0), //upper right corner
      MakeColor(255, c), //fully opaque color
      MakeColor(0, c)); //fully transparent color
graphics.FillRectangle(brush, MakeRect(0, 0, w, h));

The linear gradient brush fills the entire rectangle, which would be fine if it continued to fill the rest of the rectangle with the final (transparent) color; but instead it wraps around:

alt text

i have my LinearGradientBrush how i like, i just want to FillTriangle or FillPolygon, rather than FillRectangle. Except there is no FillTriangle or FillPolygon, only FillRectangle, and FillEllipse.

See also

link text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Oo萌小芽oO 2024-10-19 23:21:18

图形库中有一个 FillPolygon。我认为你应该能够这样做:

brush = new LinearGradientBrush(
      MakePoint(x, y), 
      MakePoint(0, h), 
      MakeColor(255, c), //fully opaque color
      MakeColor(0, c)); //fully transparent color

graphics.FillPolygon(brush, new PointF[] {
        new PointF(0, 0),
        new PointF(0, h),
        new PointF(w, h)
    });

There is a FillPolygon in the Graphics library. I think you should be able to do it like this:

brush = new LinearGradientBrush(
      MakePoint(x, y), 
      MakePoint(0, h), 
      MakeColor(255, c), //fully opaque color
      MakeColor(0, c)); //fully transparent color

graphics.FillPolygon(brush, new PointF[] {
        new PointF(0, 0),
        new PointF(0, h),
        new PointF(w, h)
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文