网学网为需要ASP.net的朋友们搜集整理了VC.NET的GDI+编程入门教程之图形相关资料,希望对各位网友有所帮助!
基于直线的图形public: void DrawRectangle(Pen *pen, Rectangle rect); |
图一、长方形说明图示 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); Rectangle Rect(20, 20, 248, 162); e->Graphics->DrawRectangle(penCurrent, Rect); } |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { e->Graphics->DrawRectangle(new Pen(Color::Red), Rectangle(20, 20, 248, 162)); } |
图二、绘制的长方形效果图 |
public: void DrawRectangle(Pen *pen, int x, int y, int width, int height); public: void DrawRectangle(Pen *pen, float x, float y, float width, float height); |
图三、Windows坐标系统 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { e->Graphics->DrawRectangle(new Pen(Color::Red), 20, 20, 248, 162); } |
public: void DrawRectangles(Pen *pen, Rectangle rects[]); public: void DrawRectangles(Pen *pen, RectangleF rects[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); Rectangle Rect[] = { Rectangle(20, 20, 120, 20), Rectangle(20, 50, 120, 30), Rectangle(20, 90, 120, 40), Rectangle(20, 140, 120, 60) }; e->Graphics->DrawRectangles(penCurrent, Rect); } |
图四、一系列长方形效果图 |
图五、直线示意图 |
public: void DrawLine(Pen *pen, Point pt1, Point pt2); public: void DrawLine(Pen *pen, PointF pt1, PointF pt2); public: void DrawLine(Pen *pen, int x1, int y1, int x2, int y2); public: void DrawLine(Pen *pen, float x1, float y1, float x2, float y2); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawLine(penCurrent, 20, 20, 205, 20); penCurrent = new Pen(Color::Green); e->Graphics->DrawLine(penCurrent, 40, 40, 225, 40); penCurrent = new Pen(Color::Blue); e->Graphics->DrawLine(penCurrent, 30, 60, 215, 60); } |
图六:绘制三条直线 |
public: void DrawLines(Pen *pen, Point points[]); public: void DrawLines(Pen *pen, PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Point Coordinates[] = { Point(20, 10), Point(205, 20), Point(40, 40), Point(225, 60), Point(30, 80), Point(215, 100) }; Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawLines(penCurrent, Coordinates); } |
图七、系列直线效果图 |
public: void DrawPolygon(Pen *pen, Point points[]); public: void DrawPolygon(Pen *pen, PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Point Pt[] = { Point(20, 50), Point(180, 50), Point(180, 20), Point(230, 70), Point(180, 120), Point(180, 90), Point(20, 90) }; Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawPolygon(penCurrent, Pt); } |
图八、多边形效果图 |
图九、椭圆示意图 |
public: void DrawEllipse(Pen *pen, Rectangle rect); public: void DrawEllipse(Pen *pen, RectangleF rect); public: void DrawEllipse(Pen *pen, int x, int y, int width, int height); public: void DrawEllipse(Pen *pen, float x, float y, float width, float height); |
图十、函数参数示意图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawEllipse(penCurrent, Rectangle(20, 20, 226, 144)); } |
图十一、代码运行效果图 |
图十二、饼图示意图 |
public: void DrawPie(Pen *pen, Rectangle rect,float startAngle,float sweepAngle); public: void DrawPie(Pen *pen, RectangleF rect, float startAngle,float sweepAngle); public: void DrawPie(Pen *pen,int x,int y,int width,int height, int startAngle, int sweepAngle); public: void DrawPie(Pen *pen, float x, float y, float width, float height, float startAngle, float sweepAngle); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawPie(penCurrent, 20, 20, 200, 100, 45, 255); } |
图十三、饼图效果 |
图十四、弧线示意图 |
public: void DrawArc(Pen *pen, Rectangle rect, float startAngle, float sweepAngle); public: void DrawArc(Pen *pen, RectangleF rect, float startAngle, float sweepAngle); public: void DrawArc(Pen *pen, int x, int y, int width, int height, int startAngle, int sweepAngle); public: void DrawArc(Pen *pen, float x, float y, float width, float height, float startAngle, float sweepAngle); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Red); e->Graphics->DrawArc(penCurrent, 20, 20, 200, 150, 225, 200); } |
图十五、程序效果图 |
图十六、曲线示意图 |
public: void DrawCurve(Pen *pen, Point points[]); public: void DrawCurve(Pen *pen, PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point( 40, 42), Point(188, 246), Point(484, 192), Point(350, 48) }; e->Graphics->DrawCurve(penCurrent, pt); } |
图十七、曲线效果图 |
public: void DrawCurve(Pen *pen, Point points[], float tension); public: void DrawCurve(Pen *pen, PointF points[], float tension); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point(40, 42), Point(188, 246),Point(484, 192), Point(350, 48) }; e->Graphics->DrawCurve(penCurrent, pt, 0.00F); } |
图十八、代码运行效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point(40, 42), Point(188, 246),Point(484, 192), Point(350, 48) }; e->Graphics->DrawCurve(penCurrent, pt, 2.15F); } |
图十九、代码运行效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); PointF pt[] = { PointF(20.00F, 322.00F), PointF(124, 24),PointF(214, 242), PointF(275, 28), PointF(380.00F, 322.00F) }; e->Graphics->DrawCurve(penCurrent, pt); } |
图二十、代码运行效果图 |
public: void DrawCurve(Pen *pen, PointF[] points, int offset, int numberOfSegments); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); PointF pt[] = { PointF(20.00F, 322.00F), PointF(124, 24),PointF(214, 242), PointF(275, 28), PointF(380.00F, 322.00F) }; e->Graphics->DrawCurve(penCurrent, pt, 1, 2); } |
图二十一、代码运行效果图 |
public: void DrawCurve(Pen *pen, Point[] points, int offset, int numberOfSegments, float tension); public: void DrawCurve(Pen *pen, PointF[] points, int offset, int numberOfSegments, float tension); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); PointF pt[] = { PointF(20.00F, 322.00F), PointF(124, 24),PointF(214, 242), PointF(275, 28),PointF(380.00F, 322.00F) }; e->Graphics->DrawCurve(penCurrent, pt, 0, 4, 0); } |
图二十二、代码运行效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); PointF pt[] = { PointF(20.00F, 322.00F), PointF(124, 24), PointF(214, 242), PointF(275, 28), PointF(380.00F, 322.00F) }; e->Graphics->DrawCurve(penCurrent, pt, 1, 3, 1.750F); } |
图二十三、代码运行效果图 |
图二十四、贝赛尔曲线 |
图二十五、贝赛尔曲线绘制说明图 |
public: void DrawBezier(Pen *pen, Point pt1, Point pt2, Point pt3, Point pt4); public: void DrawBezier(Pen *pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4); public: void DrawBezier(Pen *pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt1 = Point(20, 12), pt2 = Point(88, 246), pt3 = Point(364, 192), pt4 = Point(250, 48); e->Graphics->DrawBezier(penCurrent, pt1, pt2, pt3, pt4); } |
图二十六、贝赛尔曲线效果图 |
public: void DrawBeziers(Pen *pen, Point points[]); public: void DrawBeziers(Pen *pen, PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point(20, 12), Point(88, 246), Point(364, 192), Point(250, 48) }; e->Graphics->DrawBeziers(penCurrent, pt); } |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point( 10, 5), Point(340, 60), Point(320, 148), Point(150, 120), Point(24, 220), Point(250, 150), Point(304, 240) }; e->Graphics->DrawBeziers(penCurrent, pt); } |
图二十七、代码运行效果图 |
public: void DrawClosedCurve(Pen *pen, Point points[]); public: void DrawClosedCurve(Pen *pen, PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point(40, 42), Point(188, 246), Point(484, 192), Point(350, 48) }; e->Graphics->DrawClosedCurve(penCurrent, pt); } |
图二十八、代码运行效果图 |
图二十九、直线连接的封闭图形 |
public: void DrawClosedCurve(Pen *pen, Point points[], float tension, FillMode fillmode); public: void DrawClosedCurve(Pen *pen, PointF points[], float tension, FillMode fillmode); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; Pen *penCurrent = new Pen(Color::Red); Point pt[] = { Point(40, 42), Point(188, 246), Point(484, 192), Point(350, 48) }; e->Graphics->DrawClosedCurve(penCurrent, pt, 0.75F, FillMode::Winding); } |
图三十、代码运行效果图 |