C# GDI+技术
C# GDI+技术
GDI+概述
- System.Drawing--包括与基本画图功能相关的大多数类、结构、枚举和托付。
- System.Drawing.Drawing2D--为大多数高级2D和矢量画图操作提供了支持,包括消除锯齿、几何转换和图形路径。
- System.Drawing.Imaging--帮助处理图像(位图和GIF文件等)的各种类。
- System.Drawing.Printing--把打印机或打印预览窗体作为输出设备时使用的类。
- System.Drawing.Design--一些提前定义的对话框、属性表和其它用户界面元素,与在设计期间扩展用户界面相关。
- System.Drawing.Text--对字体和字体系列运行更高级操作的类。
基本图形绘制
Graphics类封装了绘制直线、曲线、图形、图像和文本的方法,是GDI+实现绘制直线、曲线、图形、图像和文本的类。是进行一切GDI+操作的基础类。
绘制直线
- public void DrawLine(Pen pen, Point pt1,Point pt2)
- pen:Pen对象,确定线条颜色、宽度和样式。
- pt1:Point结构,表示要连接的第一个点。
- pt2:Point结构,表示要连接的第二个点。
- Public void DrawLine(Pen pen,int x1,int y1,int x2,int y2)
绘制直线的演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Blue, 2);
- graphics.DrawLine(myPen, 50, 30, 170, 30);
- }
绘制矩形
- public void DrawRectangle(Pen pen,Rectangle rect)
- pen:Pen对象,确定线条颜色、宽度和样式。
- rect:表示要绘制矩形的Rectangle结构。
- Rectangle rect = new Rectangle(0, 0, 80, 50);
(2)绘制由坐标对、宽度和高度指定的矩形。
- public void DrawRectangle(Pen pen, int x, int y, int width, int height)
- pen:Pen对象,确定线条颜色、宽度和样式。
- x:要绘制矩形的左上角x坐标。
- y:要绘制矩形的左上角y坐标。
- width和height分别表示宽度和高度。
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Blue, 2);
- graphics.DrawRectangle(myPen, 70, 20, 80, 50);
- }
绘制椭圆
主要用来绘制边界由Rectangle结构指定的椭圆。
- public void DrawEllipse(Pen pen, Rectangle rect)
(2)绘制一个由边框(该边框由一对坐标、高度和宽度指定)定义的椭圆。
- public void DrawEllipse(Pen pen, int x, int y, int width, int height)
绘制椭圆的演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Blue, 3);
- Rectangle myRectangle = new Rectangle(70, 20, 100, 60);
- graphics.DrawEllipse(myPen, myRectangle);
- }
绘制圆弧
- public void DrawArc(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
- pen:Pen对象,确定线条颜色、宽度和样式。
- rect:Rectangle结构,定义椭圆边界。
- startAngle:从x轴到弧线的起始点沿顺时针方向度量的角(以度为单位)。
- sweepAngle:从startAngle參数到弧线的结束点沿顺时针方向度量的角(以度为单位)。
- public void DrawArc(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
绘制圆弧的实例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Blue, 5);
- Rectangle myRectangle = new Rectangle(70, 20, 100, 60);
- graphics.DrawArc(myPen, myRectangle,210,120);
- }
绘制多边形
Graphics类提供DrawPolygon方法,Pen对象存储用于呈现多边形的线条属性,如宽度和颜色等,Point(或PointF)对象数组存储多边形的各个顶点。
可重载。
- public void DrawPolygon(Pen pen, Point[] pints)
(2)绘制由一组PointF结构定义的多边形。
- public void DrawPolygon(Pen pen, PointF[] pints)
绘制多边形演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Red, 5);
- Point point1 = new Point(80, 20);
- Point point2 = new Point(40, 50);
- Point point3 = new Point(80, 80);
- Point point4 = new Point(160, 80);
- Point point5 = new Point(200, 50);
- Point point6 = new Point(160, 20);
- Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
- graphics.DrawPolygon(myPen, myPoints);
- }
绘制基数样条
- public void DrawCurve(Pen pen, Point[] points)
(2)使用指定的张力,绘制经过一组指定Point结构的基数样条。
- public void DrawCurve(Pen pen, Point[] points, float tension)
- public void DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments)
- offset:从points參数数组中的第一个元素到曲线中起始点的偏移量。
- numberOfSegments:起始点之后要包括在曲线中的段数。
- public void DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension)
绘制基数样条演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Red, 5);
- Point point1 = new Point(50, 20);
- Point point2 = new Point(60, 30);
- Point point3 = new Point(70, 25);
- Point point4 = new Point(100, 50);
- Point point5 = new Point(130, 30);
- Point point6 = new Point(150, 45);
- Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
- graphics.DrawCurve(myPen, myPoints, 1.0F);
- }
绘制贝赛尔样条
- public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
4个Point点分别表示起始点、第一个控制点、第二个控制点和结束点。
(2)绘制由4个表示点的有序坐标对定义的贝塞尔样条。
- public void DrawBezier(Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
x2,y2及x3,y3分别表示第1个、第2个控制点对应坐标。顺序和第一种方法类似。
绘制贝塞尔样条演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- Pen myPen = new Pen(Color.Red, 5);
- float startX = 50.0F;
- float startY = 80.0F;
- float controlX1 = 150.0F;
- float controlY1 = 20.0F;
- float controlX2 = 230.0F;
- float controlY2 = 50.0F;
- float endX = 190.0F;
- float endY = 80.0F;
- graphics.DrawBezier(myPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY);
- }
绘制图形路径
- public void DrawPath(Pen pen, GraphicsPath path)
- pen:Pen对象。确定线条颜色、宽度和样式。
- path:要绘制的GraphicsPath图形路径。
绘制图形路径演示样例代码:
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics graphics = this.CreateGraphics();
- GraphicsPath myGraphicsPath = new GraphicsPath();
- Pen myPen = new Pen(Color.Blue, 1);
- Point[] myPoints = { new Point(15, 30), new Point(30, 40), new Point(50, 30) };
- myGraphicsPath.AddArc(15, 20, 80, 50, 210, 120);
- myGraphicsPath.StartFigure();
- myGraphicsPath.AddCurve(myPoints);
- myGraphicsPath.AddString("图形路径", new FontFamily("华文行楷"), (int)FontStyle.Underline, 50, new PointF(20, 50), new StringFormat());
- myGraphicsPath.AddPie(180,20,80,50,210,120);
- graphics.DrawPath(myPen, myGraphicsPath);
- }
C# GDI+技术的更多相关文章
- MVC的验证(模型注解和非侵入式脚本的结合使用) .Net中初探Redis .net通过代码发送邮件 Log4net (Log for .net) 使用GDI技术创建ASP.NET验证码 Razor模板引擎 (RazorEngine) .Net程序员应该掌握的正则表达式
MVC的验证(模型注解和非侵入式脚本的结合使用) @HtmlHrlper方式创建的标签,会自动生成一些属性,其中一些属性就是关于验证 如图示例: 模型注解 通过模型注解后,MVC的验证,包括前台客 ...
- C# :GDI+技术生成复杂型彩色验证码(转载)
该类是生成一个验证码的类,集合了网上大部分的C#关于GDI+的文章进行多次改进,现在已经形成了可在生产环节中使用的验证码. 该验证码加入了背景噪点,背景噪点曲线和直线,背景噪点文字以及扭曲,调暗,模糊 ...
- GDI+技术
GDI+是GDI的后继者,它是一种构成 Windows XP 操作系统的子系统的应用程序编程接口. 一般来说有3种基本类型的绘图界面,分别为Windows 窗体上的控件.要发送给打印机的页面和内存中的 ...
- 使用GDI技术创建ASP.NET验证码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
- C#-gdi绘图,双缓冲绘图,Paint事件的触发
一. 画面闪烁问题与双缓冲技术 1.1 导致画面闪烁的关键原因分析: 1 绘制窗口由于大小位置状态改变进行重绘操作时 绘图窗口内容或大小每改变一次,都要调用Paint事件进行重绘操作,该操作会使画面 ...
- C#-gdi画图,双缓冲画图,Paint事件的触发---ShinePans
在使用gdi技术画图时,有时会发现图形线条不够流畅,或者在改变窗口大小时会闪烁不断的现象.(Use DoubleBuffer to solve it!) ...
- Excel阅读模式/单元格行列指示/聚光灯开发 技术要点再分享
1. 引言 文题中所谓技术要点再分享,本意是想在大神Charltsing Liu的博文“简单介绍Excel单元格行列指示的实现原理(俗称聚光灯功能)”的基础上写一点个人开发体会.写本文的初衷有三点,一 ...
- WPF GDI+字符串绘制成图片(二)
原文:WPF GDI+字符串绘制成图片(二) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83 ...
- WPF GDI+字符串绘制成图片(一)
原文:WPF GDI+字符串绘制成图片(一) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83 ...
随机推荐
- bzoj 5210(树链刨分下做个dp)
5210: 最大连通子块和 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 211 Solved: 65[Submit][Status][Discus ...
- hdu 4557 暴力
题意: 作为2013年699万应届毕业生中的一员,由于宏观经济的不景气,小明在毕业当天就华丽丽地失业了! 经历了千难万苦的求职过程,小明特别能理解毕业生的就业之难,所以,他现在准备创建一家专门针对IT ...
- hdu 2732 最大流 **
题意:题目是说一个n*m的迷宫中,有每个格子有柱子.柱子高度为0~3,高度为0的柱子是不能站的(高度为0就是没有柱子)在一些有柱子的格子上有一些蜥蜴,一次最多跳距离d,相邻格子的距离是1,只要跳出迷宫 ...
- Eclipse 工具下Maven 项目的快速搭建
Eclipse 工具下Maven 项目的搭建 参考博文:https://www.cnblogs.com/iflytek/p/7096481.html 什么是Maven项目 简单来说,传统的Web项目: ...
- CentOS7.0安装Nginx-1.12.0
一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...
- Codeforces Round #257 (Div. 2 ) B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- ZOJ3673:1729
1729 is the natural number following 1728 and preceding 1730. It is also known as the Hardy-Ramanuja ...
- cocos2d-x3.0 RichText
.h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...
- C#程序集系列06,程序集清单,EXE和DLL的区别
CLR在加载程序集的时候会查看程序集清单,程序集清单包含哪些内容呢?可执行文件和程序集有什么区别/ 程序集清单 □ 查看程序集清单 →清空F盘as文件夹中的所有内容→创建MainClass.cs文件→ ...
- C#中使用NLua z
直接下载NLua编译好的版本在c#项目中使用,运行的时候会提示无法加载lua52.dll,但lua52.dll这个文件又是在运行目录下的. 其实NLua不是无法加载lua52.dll本身,而是找不到l ...