3.使用GDI+畫曲線


     來源:http://www.cnblogs.com/kiny/articles/2506700.html

1.畫貝塞爾曲線

DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
DrawBezier(Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
DrawBezier(Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
DrawBeziers(Pen pen, Point[] points)
DrawBeziers(Pen pen, PointF[] points)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //創建畫板從Paint事件中的直接引用Graphics對象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定義畫筆
            Pen pen = new Pen(Color.White, 3.0f);

            Point p1 = new Point(100, 100);
            Point p2 = new Point(200, 400);
            Point p3 = new Point(400, 400);
            Point p4 = new Point(500, 100);

            graphics.DrawBezier(pen, p1, p2, p3, p4);
        }

2. 繪制曲線

        DrawCurve(Pen pen, Point[] points)
        DrawCurve(Pen pen, PointF[] points)
        
        //tension:大於或等於 0.0F 的值,該值指定曲線的張力。
        DrawCurve(Pen pen, Point[] points, float tension)
        DrawCurve(Pen pen, PointF[] points, float tension)

        //offset:從 points 參數數組中的第一個元素到曲線中起始點的偏移量。
        //numberOfSegments: 起始點之后要包含在曲線中的段數。
        DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments)
        DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension)
        DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //創建畫板從Paint事件中的直接引用Graphics對象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定義畫筆
            Pen pen = new Pen(Color.White, 3.0f);

            //定義點坐標
            Point[] points = { 
                         new Point(50,50),
                         new Point(100,25),
                         new Point(200,5),
                         new Point(250,50),
                         new Point(300,100),
                         new Point(350,200),
                         new Point(250,250)
                     };
            graphics.DrawCurve(pen, points, 0.5f);
        }

     第三個參數是張力(平滑度),如果等於0.0的話就是線段了,相當於DrawLines,越接近1.0越光滑。如果大於1.0的出現異常結果。下面是從0.0,1.0的效果圖

3.畫封閉曲線

DrawClosedCurve(Pen pen, Point[] points)
DrawClosedCurve(Pen pen, PointF[] points)

//tension:大於或等於 0.0F 的值,該值指定曲線的張力。
//fillmode:System.Drawing.Drawing2D.FillMode 枚舉的成員,它確定填充曲線的方式。需要此參數但被忽略。
DrawClosedCurve(Pen pen, Point[] points, float tension, FillMode fillmode)
DrawClosedCurve(Pen pen, PointF[] points, float tension, FillMode fillmode)
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //創建畫板從Paint事件中的直接引用Graphics對象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定義畫筆
            Pen pen = new Pen(Color.White, 3.0f);

            //定義點坐標
            Point[] points = { 
                         new Point(50,50),
                         new Point(100,25),
                         new Point(200,5),
                         new Point(250,50),
                         new Point(300,100),
                         new Point(350,200),
                         new Point(250,250)
                     };
            graphics.DrawClosedCurve(pen, points);
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM