C++ 中的渐变填充自定义绘图建造者XE

发布于 2024-11-17 11:59:58 字数 548 浏览 5 评论 0原文

我借助下面的代码在 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);

I have drawn a custom drawing 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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-11-24 11:59:58

使用带有剪切区域的 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 );

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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文