windows 如何使用 C++ 绘制填充多边形?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7622809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to draw filled polygon using c++?
提问by Marco
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:
我是 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 );}
How can I draw filled polygons using techniques similar to what I have learned so far?
如何使用与我目前学到的类似的技术绘制填充多边形?
回答by David Heffernan
Call Graphics.FillPolygon()
. You will need a brush rather than a pen and you must put your points into a point array Point[]
.
打电话Graphics.FillPolygon()
。您将需要刷子而不是笔,并且必须将点放入点数组中Point[]
。
The sample code from MSDN is like this:
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 );