2

我在下面的代码的帮助下在 C++ Builder XE 中绘制了一个自定义绘图,但现在我想用渐变填充颜色填充它。

PaintBox1->Canvas->Pen->Color = RGB (187, 187, 187);

PaintBox1->Canvas->MoveTo(0, 8);
PaintBox1->Canvas->LineTo(10, 0);
PaintBox1->Canvas->LineTo(10, 5);
PaintBox1->Canvas->LineTo(21, 5);
PaintBox1->Canvas->MoveTo(0, 8);
PaintBox1->Canvas->LineTo(10, 15);
PaintBox1->Canvas->LineTo(10, 10);
PaintBox1->Canvas->LineTo(21, 10);
PaintBox1->Canvas->LineTo(21, 5);
4

1 回答 1

2

使用带有剪切区域的 GradientFillCanvas 可能是最简单的。请参阅以下链接:

http://docwiki.embarcadero.com/VCL/en/GraphUtil.GradientFillCanvas

http://www.delphigroups.info/2/12/324143.html

所以你会做这样的事情:

POINT polygon[8] = {{0,8},{10,0},{10,5},{21,5},{21,10},{10,10},{10,15},{0,8}};
HRGN rgn = CreatePolygonRgn( polygon, 8, WINDING );
SelectClipRgn(PaintBox1->Canvas.Handle, rgn);
TRect gradientRect(0,0,21,15);
GradientFillCanvas( PaintBox1->Canvas, start_color, end_color, gradientRect, gradient_direction );
SelectClipRgn(PaintBox1->Canvas.Handle, NULL);
DeleteObject(rgn);
//the polygon could also be drawn instead of using LineTo
PaintBox1->Canvas->Polygon( polygon, 8 );
于 2011-06-30T20:12:12.513 回答