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 ...
随机推荐
- ajax中error函数参数详解
xhr.status和error函数中的status是不一样的,error函数中的status主要包括:"success"."notmodified".&quo ...
- VirtualBox为虚拟OS硬盘扩容
1.关闭虚拟OS. 2.进入到在VirtualBox的安装路径,执行命令例子如: VBoxManage.exe modifyhd F:\VM\Debian7.2.vdi --resize 40000 ...
- POJ3421(质因数分解)
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6501 Accepted: 2023 D ...
- c# OrderBy 实现List升序降序
本文转载自:http://blog.csdn.net/chadcao/article/details/8730132 1)前台代码 <%@ Page Language="C#" ...
- 机器学习:集成学习(集成学习思想、scikit-learn 中的集成分类器)
一.集成学习的思想 集成学习的思路:一个问题(如分类问题),让多种算法参与预测(如下图中的算法都可以解决分类问题),在多个预测结果中,选择出现最多的预测类别做为该样本的最终预测类别: 生活中的集成思维 ...
- Regexp:目录
ylbtech-Regexp:目录 1.返回顶部 1. http://www.runoob.com/regexp/regexp-tutorial.html 2. 2.返回顶部 3.返回顶部 4 ...
- web.xml中classpath表示什么样的路径
首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties ...
- perform-maintence-on-replica-set-members
https://docs.mongodb.com/v3.0/tutorial/perform-maintence-on-replica-set-members/ 1 oplog 改变大小 --详见mo ...
- 为什么每个浏览器都有Mozilla字样
你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样?Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ( ...
- ehcache缓存入门学习
ehcache缓存入门学习 1,概念 特性 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 主要的特性有:1. 快速2 ...