获取Graphics对象的方法
在做自定义控件时或者GDI+的时候经常会遇到获取Graphics实例的问题。一般有三种获取方式
1、从Paint事件的参数中获取。
窗体和许多控件都有一个Paint事件,有一个PaintEventArgs类型的参数e
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//获取Graphic对象
Graphics g = e.Graphics;
//书写绘图代码
g.DrawLine(new Point(0,0),new Point(1,1));
//释放Graphic对象占用的资源
g.Dispose();
}
2. 用CreateGraphics方法创建。
如果需要在Paint方法以外绘图,可以通过控件或窗体的CreateGraphics方法来获取Graphics对象
using(Graphics g=new Control().CreateGraphics())
{
}
3. 对Image对象调用Graphics.FromImage获取。
//创建Image对象
Bitmap image1 = new Bitmap("football.jpg");
//窗体的绘图对象
Graphics formE = e.Graphics;
4、通过Graphics的FromHwnd函数
HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
using (Graphics g = Graphics.FromHwnd(NullHandleRef.Handle))
{
}
获取Graphics对象的方法的更多相关文章
- 获取InputStream对象的方法
获取InputStream对象的方法 getResourceAsStream(String path) 默认path路径位于Class所在Module的src目录下 . InputStream is ...
- C#创建Graphics对象的方法
方法一.利用控件或窗体的Paint事件中的PainEventArgs 在窗体或控件的Paint事件中接收对图形对象的引用,作为PaintEventArgs(PaintEventArgs指定绘制控件所用 ...
- spring获取ApplicationContext对象的方法——ApplicationContextAware
一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...
- 获取applicationContext对象的方法
方法一:在初始化时保存ApplicationContext对象 代码: ApplicationContext ac = new FileSystemXmlApplicationContext(&quo ...
- 反射①:如何获取class对象六种方法
获取class对象的六种方法 了解:class类——是Java反射机制的入口,封装了一个类或接口的运行信息,通过调用Class类的方法可以获取这些信息,其特点如下: 1.该类在java.lang包中: ...
- 利用servlet产生随机数,原理是获取Graphics对象进行绘图
public class ResonpeRandomImgDemo extends HttpServlet { int width=100; int height=30; public void do ...
- js中获取事件对象的方法小结
原文地址:http://jingyan.baidu.com/article/d8072ac4594d6cec95cefdac.html 事件对象 的获取很简单,很久前我们就知道IE中事件对象是作为全局 ...
- Action中获取servletAPI对象的方法
1.ServletActionContext:可以从中获取当前Action对象需要的一切ServletAPI的相关对象: 常用的方法: 1.获取HttpServletRequest:ServletAc ...
- Java中通过Class类获取Class对象的方法详解
方式1:通过Object类的getObject()方法 Person p = new Person(); Class c = p.getClass(); 方式2: 通过 类名.class 获取到字节码 ...
随机推荐
- C# ListView得到选中项及子项
private void listViewEx_MouseClick(object sender, MouseEventArgs e) { ListViewItem lv = listViewEx.G ...
- 25个实用的jQuery技巧和解决方案
1. 去除页面的右键菜单 $(document).ready(function(){ $(document).bind(“contextmenu”,function(e){returnfalse;}) ...
- 坑爹的 SONY AS100V GPS
事情是这样的,为了记录自己的生活,也是出于对视频编辑的兴趣,买了一台 SONY 的 AS100V 运动摄像机. 公司到货,回家路上拍了一段,回家兴冲冲的连上电脑,想看看 GPS 数据,发现是 SONY ...
- python opencv 利用Lab空间把春天的场景改为秋天
前一段时间实现了Reinhard颜色迁移算法,感觉挺有意思的,然后在代码上随意做了一些更改,有了一些发现,把Lab通道的a通道值改为127左右,可以将绿色改为黄色,而对其他颜色的改动非常小,因此可以将 ...
- 基于layerpage 前后端异步分页
#下载jquery 和 layerpage1.核心分页方法 laypage({ cont: 'page1', //容器.值支持id名.原生dom对象,jquery对象. pages: json.tot ...
- Thinkphp回顾(五)之前台模板中的基本语法
一.导入CSS和JS文件 的三种方式 (了解) 1.link方式(常规) <link rel=’stylesheet’ type=’text/css’ href=’__PUBLIC__/Js/ ...
- PHP Problem with the SSL CA cert (path? access rights?)
1.php使用curl模块报错问题 开发遇到问题,直接使用系统的curl命令正常,使用php的curl模块报错 错误:PHP Problem with the SSL CA cert (path? a ...
- 7.dotnet core 如何发邮件
需要用到的Nuget包 "MailKit": "1.8.1", 方法 /// <summary> /// 发送邮件(支持Html发送,支持添加一个附 ...
- 5.对与表与表之间的关系,efcore是如何处理的
public class Account { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Accoun ...
- Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...