C#利用GDI绘制常见图形和文字
作者:Kimisme 时间:2023-04-09 20:44:40
废话不多说,我们先来认识一下这个GDI+,看看它到底长什么样。
GDI+:Graphics Device Interface Plus也就是图形设备接口,提供了各种丰富的图形图像处理功能;在C#.NET中,使用GDI+处理二维(2D)的图形和图像,使用DirectX处理三维(3D)的图形图像,图形图像处理用到的主要命名空间是System . Drawing:提供了对GDI+基本图形功能的访问,主要有Graphics类、Bitmap类、从Brush类继承的类、Font类、Icon类、Image类、Pen类、Color类等.
大概了解了什么是GDI+后,我们直接用几个示例,来向大家展示它能做什么吧。
1.画一条直线
private void btnDrawLine_Click(object sender, EventArgs e)
{
//创建一个画图图面
Graphics g = this.CreateGraphics();
//创建一只笔
Pen pen = new Pen(Brushes.Red);
//直线的两个坐标
Point pointStart = new Point(10, 10);
Point pointEnd = new Point(50, 50);
//开始画
g.DrawLine(pen, pointStart, pointEnd);
}
2.画一个矩形
private void btnDrawRectangle_Click(object sender, EventArgs e)
{
//创建一个画图图面
Graphics g = this.CreateGraphics();
//创建一只笔
Pen pen = new Pen(Brushes.DeepSkyBlue);
//确定矩形的起点、长和高
g.DrawRectangle(pen, 50, 50, 60, 30);
}
3.画一个字符串
private void btnDrawString_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Font font = new Font("华为宋体", 12);
//Point一样,只是值是浮点类型
PointF point = new PointF(50, 50);
g.DrawString("我是Kimisme", font, Brushes.Coral, point);
}
4.画一个扇形
private void btnDrawSector_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawPie(new Pen(Brushes.Green),
new Rectangle(new Point(100, 70),
new Size(50, 50)), 60, 90);
}
标签:C#,GDI
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android TabHost组件使用方法详解
2023-11-14 20:01:13
![](https://img.aspxhome.com/file/2023/3/114373_0s.jpg)
SpringBoot+Shiro+LayUI权限管理系统项目源码
2021-07-13 16:35:19
![](https://img.aspxhome.com/file/2023/6/95976_0s.png)
MyBatis注解实现动态SQL问题
2023-08-19 02:34:09
基于servlet实现统计网页访问次数
2021-11-05 08:35:13
![](https://img.aspxhome.com/file/2023/7/82047_0s.jpg)
java实现读取、删除文件夹下的文件
2021-12-06 20:07:48
Java BigDecimal案例详解
2021-09-15 12:03:43
![](https://img.aspxhome.com/file/2023/9/63509_0s.png)
C#实现合并多张图片为GIF动态图
2022-12-13 04:16:35
![](https://img.aspxhome.com/file/2023/2/106462_0s.png)
详解Java中的迭代迭代器Iterator与枚举器Enumeration
2021-08-21 19:32:44
解决mybatis plus 驼峰式命名规则问题
2022-09-29 11:24:34
![](https://img.aspxhome.com/file/2023/2/62712_0s.png)
Java中Cookie和Session的那些事儿
2022-09-24 08:24:54
![](https://img.aspxhome.com/file/2023/7/78377_0s.png)
因Spring AOP导致@Autowired依赖注入失败的解决方法
2022-10-24 19:44:11
Android 仿网易新闻客户端分类排序功能
2023-12-19 13:07:52
![](https://img.aspxhome.com/file/2023/4/138724_0s.gif)
Java设计模式之java组合模式详解
2022-05-02 07:52:38
![](https://img.aspxhome.com/file/2023/2/115972_0s.png)
Java基于动态规划法实现求最长公共子序列及最长公共子字符串示例
2021-10-11 22:20:17
![](https://img.aspxhome.com/file/2023/3/90033_0s.png)
C#创建临时文件的方法
2023-06-16 14:32:36
Android之复选框对话框用法实例分析
2023-10-03 05:07:03
![](https://img.aspxhome.com/file/2023/1/84751_0s.png)
C# winfrom 模拟ftp文件管理实现代码
2023-07-15 16:29:48
SpringMVC加载控制与Postmand的使用和Rest风格的引入及RestFul开发全面详解
2021-10-14 16:45:44
![](https://img.aspxhome.com/file/2023/5/79815_0s.png)
详解Java使用Jsch与sftp服务器实现ssh免密登录
2023-11-24 18:34:18
Android自定义View展开菜单功能的实现
2022-02-08 06:28:49
![](https://img.aspxhome.com/file/2023/7/138307_0s.gif)