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 ...
随机推荐
- Python 面向对象编程——继承和多态
<基本定义> 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超 ...
- Web2.0应用程序的7条原则
个人看好Web的发展潜力,本文字摘自<Collective Intelligence 实战> 网络是平台 使用传统许可模式软件的公司或用户必须运行软件.定期更新至最新版本,以及扩展它来满足 ...
- QQ怎么 发送 已经录好的视频
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha QQ发送 已经录好的视频 直接放过去,对方是需要下载的. 只有通过QQ录制的,才是直接就 ...
- 【dijkstra优化/次短路径】POJ3255-Roadblocks
[题目大意] 给出一张无向图,求出从源点到终点的次短边. [思路] 先来谈谈Dijkstra的优化.对于每次寻找到当前为访问过的点中距离最短的那一个,运用优先队列进行优化,避免全部扫描,每更新一个点的 ...
- GNU C __attribute__ 机制简介
摘要: 在学习linux内核代码及一些开源软件的源码(如:DirectFB),经常可以看到有关__attribute__的相关使用.本文结合自己的学习经历,较为详细的介绍了__attribute__相 ...
- java线程本地变量
ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并不是一个Thread,而是threadlocalvariable(线程局部变量).也许把它命名为Thre ...
- JDK源码学习笔记——Enum枚举使用及原理
一.为什么使用枚举 什么时候应该使用枚举呢?每当需要一组固定的常量的时候,如一周的天数.一年四季等.或者是在我们编译前就知道其包含的所有值的集合. 利用 public final static 完全可 ...
- codevs 1052 地鼠游戏 优先队列
1052 地鼠游戏 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.codevs.cn/problem/1052/ Descriptio ...
- ASP.NET 构建高性能网站 第1篇
网站优化需要考虑的方面 在用ASP.NET开发网站的时候,性能是永远需要考虑和关注的问题,性能不仅仅只是程序代码执行时候的速度,而是涉及到方方面面的东西. 就拿ASP.NET的一个请求来讲,从浏览器向 ...
- Struts2 JSONObject的使用
一.jar包 使用之前必须引入所须要的jar包,这里包含Struts2和JSONObject各自所必须的 Struts2: commons-fileupload-1.2.1.jarcommons-io ...