DrawBezier用法是什么
时间: 2024-01-20 19:04:43 浏览: 17
`DrawBezier` 方法用于在 `Graphics` 对象上绘制一条三次贝塞尔曲线。其语法如下:
```csharp
public void DrawBezier(Pen pen, float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4);
```
或者:
```csharp
public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4);
```
其中,`pen` 表示绘制曲线所使用的画笔对象;`x1`、`y1`、`x2`、`y2`、`x3`、`y3`、`x4`、`y4` 分别表示曲线的起点、第一个控制点、第二个控制点和终点的坐标;`pt1`、`pt2`、`pt3`、`pt4` 则表示曲线的起点、第一个控制点、第二个控制点和终点的 `Point` 对象。
以下是一个绘制三次贝塞尔曲线的示例代码:
```csharp
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue, 3);
Point startPoint = new Point(50, 50);
Point controlPoint1 = new Point(100, 100);
Point controlPoint2 = new Point(150, 75);
Point endPoint = new Point(200, 125);
g.DrawBezier(p, startPoint, controlPoint1, controlPoint2, endPoint);
}
```
在上面的代码中,我们创建了一个 `Graphics` 对象和一个 `Pen` 对象,然后使用 `DrawBezier` 方法绘制了一条三次贝塞尔曲线。将曲线的起点、控制点1、控制点2和终点分别表示为 `Point` 类型的对象,作为 `DrawBezier` 方法的参数传递给它。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)