【学习笔记】Windows GDI绘图(六)图形路径GraphicsPath详解(中)

上一篇【学习笔记】Windows GDI绘图(五)图形路径GraphicsPath详解(上)介绍了GraphicsPath类的构造函数、属性和方法AddArc添加椭圆弧、AddBezier添加贝赛尔曲线、AddClosedCurve添加封闭基数样条曲线、AddCurve添加开放基数样条曲线、基数样条如何转Bezier、AddEllipse添加椭圆、AddLine添加线段。

革命尚未成功,同志仍需努力!


GraphicsPath

GraphicsPath方法

AddLines添加线段

原型:

public void AddLines (params System.Drawing.Point[] points);
public void AddLines (params System.Drawing.PointF[] points);

添加一系列的线段到GraphicsPath中。

// 定义三角形的顶点
Point[] points =
         {
   
   
            new Point(150,150),
            new Point(300,300),
            new Point(0,300),
            new Point(150,150)
          };

using (var myPath = new GraphicsPath())
{
   
   
    myPath.AddLines(points);

    e.Graphics.DrawPath(penRed, myPath);
}

通过点集绘制线段
AddLines

AddPath附加路径

原型:

public void AddPath (System.Drawing.Drawing2D.GraphicsPath addingPath, bool connect);

connect,当前路径与附加的路径是否相连
将指定的GraphicsPath附加到当前Path中

Point[] myArray =
         {
   
   
     new Point(120,120),
     new Point(240,240),
     new Point(0,240),
     new Point(120,120)
 };
GraphicsPath myPath = new GraphicsPath();
myPath.AddLines(myArray);

Point[] myArray2 =
         {
   
   
     new Point(120,100),
     new Point(20,20),
     new Point(220,20),
     new Point(120,100)
 };
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);

// Add the second path to the first path.
myPath.AddPath(myPath2, false);//各自独立

// Draw the combined path to the screen.
e.Graphics.DrawPath(penRed, myPath);

myPath.Reset();
myPath.AddLines(myArray);
myPath.AddPath(myPath2, true);//相连

myPath.Transform(new Matrix(1, 0, 0, 1, 400, 0));
e.Graphics.DrawPath(penLightGreen, myPath);

AddPath

AddPie添加饼形

原型:

public void AddPie (System.Drawing.Rectangle rect, float startAngle, float sweepAngle);
public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle);
public void AddPie (float x, <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图南科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值