开发者

Gradiant fill custom drawing in C++ Builder XE

I have drawn a custom draw开发者_StackOverflowing in C++ Builder XE with the help of the code below, but now I want to fill it with gradientfill color.

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


It would probably be easiest to use GradientFillCanvas with a clipping region. See the folowing links:

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

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

So you would do something like:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜