GDI+:如何填充三角形?
我想用 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 之外。
另请参阅
i want to fill the bottom-left half of a a rectangle (i.e. a triangle):
with a LinearGradient, going from color to transparent:
Filling half a rectangle:
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:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图形库中有一个 FillPolygon。我认为你应该能够这样做:
There is a FillPolygon in the Graphics library. I think you should be able to do it like this: