我想填充矩形的左下半部分(即三角形):
使用LinearGradient,从颜色变为透明:
填充半个矩形:
我知道点(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));
线性渐变画笔填充整个矩形,如果它继续用最终(透明)颜色填充矩形的其余部分,那将是很好的;但相反它包裹着:
我有LinearGradientBrush
我喜欢的方式,我只想FillTriangle
或FillPolygon
,而不是FillRectangle
。除了没有FillTriangle或FillPolygon,只有FillRectangle和FillEllipse。
答案 0 :(得分:2)
图形库中有一个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)
});