我在下面的代码的帮助下在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);
答案 0 :(得分:1)
将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 );