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 ...
随机推荐
- leetcode 奇偶链表 python
要求空间复杂度O(1) 那就只能用指针不断改链表的指针, 不能建立新的内存 时间复杂度O(1) 一遍遍历 不能嵌套循环 我的思想是: 1 如果链表元素数量小于等于2个,那就无法操作 2 能操作的情况下 ...
- Winform 串口通讯之读卡器
老板给我的第一个硬件就是一个读卡器, 说让我做一下试试,于是从网上查了查就写了出来,相当的简单. 但是后来还有一个地磅的串口通讯,我整整搞了一天. 在窗体类的构造函数中写入 Form.CheckFor ...
- 【WIN10】使用自己的PageLoader加載Page
源碼下載:http://yunpan.cn/cFwwrT4V5rHIM 访问密码 1b97 在上一篇博客中,我已經說明了為什麼要自己寫一個PageLoader.原因就是,Frame的GoBack只是 ...
- bzoj1814: Ural 1519 Formula 1 动态规划 插头dp
http://acm.timus.ru/problem.aspx?space=1&num=1519 题目描述 一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数. ...
- 【Codeforces528D】Fuzzy Search FFT
D. Fuzzy Search time limit per test:3 seconds memory limit per test:256 megabytes input:standard inp ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- HDU 5150 Sum Sum Sum 素数
Sum Sum Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- AbstractAction
package cn.tz.action.abs; import java.io.File; import java.io.IOException; import java.text.SimpleDa ...
- ThinkPHP 数据库操作之数据表模型和基础模型 ( Model )
一.定义数据表模型 1.模型映射 要测试数据库是否正常连接,最直接的办法就是在当前控制器中实例化数据表,然后使用 dump 函数输出,查看数据库的链接状态.代码: public function te ...
- Eclipse:引用一个项目作为类库(图文教程)
前言:项目TestRoid要引用Volley项目作为类库 步骤如下: 一:选择导入Android项目 二:选择Volley项目路径导入 三:右击Volley项目,点击Properties 四: ...