winform GDI基础(一)
1获取画布
(1)从PaintEventArgs类中获取画布
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
}
(2)从Image中获取画布
Bitmap bm = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bm);
(3)使用CreateGraphics创建画布
Graphics g = this.CreateGraphics();
(4)其他方式
从设备上下文的指定句柄创建新的 System.Drawing.Graphics
public static Graphics FromHdc(IntPtr hdc);
从设备上下文的指定句柄和设备的句柄创建新的 System.Drawing.Graphics
public static Graphics FromHdc(IntPtr hdc, IntPtr hdevice);
返回指定设备上下文的 System.Drawing.Graphics
public static Graphics FromHdcInternal(IntPtr hdc);
从窗口的指定句柄创建新的 System.Drawing.Graphics
public static Graphics FromHwnd(IntPtr hwnd);
创建指定 Windows 句柄的新 System.Drawing.Graphics
public static Graphics FromHwndInternal(IntPtr hwnd);
2绘制图像
Graphics g = this.CreateGraphics();
System.Drawing.Pen pen = new System.Drawing.Pen(Color.Red, 2);
g.DrawLine();//画线
g.DrawRectangle();//画矩形
g.DrawEllipse();//画椭圆
g.DrawArc();//画扇形
3抗锯齿处理
g.SmoothingMode = SmoothingMode.HighQuality;//设置抗锯齿
g.CompositingQuality = CompositingQuality.HighQuality;//提升合成图片质量
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;//去掉文字的锯齿
4处理图像
Bitmap bm = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(bm);
System.Drawing.Pen pen = new System.Drawing.Pen(Color.Red, 4);
g.DrawLine(pen,new Point(10,10),new Point(100,100));
bm.Save(Application.StartupPath + @"\1.png");
g.Dispose();
bm.Dispose();
winform GDI基础(一)的更多相关文章
- winform GDI基础(四)简单截屏
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); G ...
- winform GDI基础(二)画带圆角的矩形框
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode ...
- winform GDI基础(三)实现画笔
在程序窗口上使用鼠标画图 private Point pStart, pEnd; private bool isAllowDraw = false; private bool isOpenPen = ...
- WinForm GDI+ 资料收集
UI(User Interface)编程在整个项目开发过程中是个颇为重要的环节,任何好的解决方案若没有良好的用户界面呈现给最终用户,那么就算包含了最先进的技术也不能算是好程序.UI编程体现在两个方面, ...
- Winform 开发基础分层框架
Winform 开发基础分层框架:
- Winform GDI+
什么是GDI+ GDI (Graphics Device Interface), 是属于绘图方面的 API (Application Programming Interface). 因为应用程序不能直 ...
- WinForm GDI+自定义控件总结(一)
前言 由于项目的原因好久没写博客了,也正是项目的原因开始系统的学习WinForm,从而接触到自定义控件的开发.自定义控件的开发有一定的难度,对开发者要求比较高,需要了解Windows运行的机制,熟悉w ...
- 《C# GDI+ 破境之道》:第一境 GDI+基础 —— 第一节:画直线
今天正式开一本新书,<C# GDI+ 破镜之道>,同样是破镜之道系列丛书的一分子. 关于GDI+呢,官方的解释是这样的: GDI+ 是 Microsoft Windows 操作系统的窗体子 ...
- Winform GDI+ 相关资料
在Visual Studio 2010中定义GDI+自定义控件——自定义控件介绍 http://www.cnblogs.com/zhangdong/archive/2010/05/20/1740177 ...
随机推荐
- js 科学计数转数字或字符串
- dockerfile mysql
FROM centos6.6-mysql5.5:0.0.4 MAINTAINER syberos:wangmo RUN mv /etc/my.cnf /etc/my.cnf.bak ADD my.cn ...
- 判断唯一约束是否是唯一的Unique
//检查 唯一约束Name //检查 唯一约束Name int count = new BLL.Funcs().GetRecordCount(string.Format("Name={0}& ...
- request_mem_region,ioremap 和phys_to_virt()
转载: request_mem_region,ioremap 和phys_to_virt() Linux在头文件include/linux/ioport.h中定义了三个对I/O内存资源进行操作的宏 ...
- 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)
Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...
- Sass和Less、Stylus的转译和语法(1)
四.Sass.LESS和Stylus转译成CSSSass.LESS和Stylus源文件(除了LESS源文件在客户端下运行之外)都不能直接被浏览器直接识别,这样一来,要正常的使用这些源文 件,就需要将其 ...
- iOS按home键后程序的状态变化
iOS 的应用里的几种状态: active: 应用在前台正常运行 background: 应用在后台,并且在执行代码. inactive: 这个状态是应用从一个状态向另一个状态的过渡 suspende ...
- python中的 ' ' 和 " "
#!/usr/bin/python import MySQLdb try: conn = MySQLdb.connect(host = 'localhost', user = 'root', pass ...
- c# 实用精华知识点全解
本文介绍c#的实用知识点 写在前面(通识) vs常用快捷键 F5 调试运行程序 ctrl F5 不调试运行程序 F11 逐条语句调试 F10 逐过程调试程序 注释快捷键 ctrl + k + c 代码 ...
- svn 撤销修改
1,更新到最新版本 不知道是哪个文件的问题时,可以svn log查看日志,基本上可以通过哪一次提交修改了哪一个文件推算出 是哪个文件的问题. 若知道是哪个文件的问题,直接svn log 文件名 大致确 ...