关闭

贝塞尔曲线gdi

234人阅读 评论(0) 收藏 举报
分类:


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的出现异常结果。


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);
        }
0
1

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4627次
    • 积分:218
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:5篇
    • 译文:0篇
    • 评论:0条