如何使用c++绘制填充多边形?

发布于 2024-12-07 13:57:05 字数 524 浏览 1 评论 0原文

我是 C++ 新手。我使用的是Visual studio Professional 2010。我学会了画线,但是这次我需要画填充多边形。我绘制线条的方式如下:

private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
                Graphics ^g = e->Graphics;  //require for drawing
                g->DrawArc(Pens::Black, i-the_size/2, j-the_size/2, the_size, the_size, 0, 90 );
                g->DrawArc(Pens::Black, i+the_size/2, j+the_size/2, the_size, the_size, 180, 90 );}

如何使用与我迄今为止学到的类似的技术绘制填充多边形?

I'm new to C++. I am using Visual studio Professional 2010. I learned to draw lines, but I need to draw filled polygon this time. The way that I drew lines is below:

private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
                Graphics ^g = e->Graphics;  //require for drawing
                g->DrawArc(Pens::Black, i-the_size/2, j-the_size/2, the_size, the_size, 0, 90 );
                g->DrawArc(Pens::Black, i+the_size/2, j+the_size/2, the_size, the_size, 180, 90 );}

How can I draw filled polygons using techniques similar to what I have learned so far?

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

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

发布评论

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

评论(1

一杯敬自由 2024-12-14 13:57:05

调用 Graphics.FillPolygon()。您将需要画笔而不是笔,并且必须将点放入点数组 Point[] 中。

来自MSDN的示例代码是这样的:

// Create solid brush.
SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

// Create points that define polygon.
Point point1 = Point(50,50);
Point point2 = Point(100,25);
Point point3 = Point(200,5);
Point point4 = Point(250,50);
Point point5 = Point(300,100);
Point point6 = Point(350,200);
Point point7 = Point(250,250);
array<Point>^ curvePoints = {point1,point2,point3,point4,point5,point6,point7};

// Draw polygon to screen.
e->Graphics->FillPolygon( blueBrush, curvePoints );

Call Graphics.FillPolygon(). You will need a brush rather than a pen and you must put your points into a point array Point[].

The sample code from MSDN is like this:

// Create solid brush.
SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

// Create points that define polygon.
Point point1 = Point(50,50);
Point point2 = Point(100,25);
Point point3 = Point(200,5);
Point point4 = Point(250,50);
Point point5 = Point(300,100);
Point point6 = Point(350,200);
Point point7 = Point(250,250);
array<Point>^ curvePoints = {point1,point2,point3,point4,point5,point6,point7};

// Draw polygon to screen.
e->Graphics->FillPolygon( blueBrush, curvePoints );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文