开发者

GDI+: How to fill a triangle?

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

GDI+: How to fill a triangle?

with a L开发者_运维知识库inearGradient, going from color to transparent:

GDI+: How to fill a triangle?

Filling half a rectangle:

GDI+: How to fill a triangle?

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:

GDI+: How to fill a triangle?

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


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)
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜