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();

  

最新文章

  1. Entity Framework 实体框架的形成之旅--实体数据模型 (EDM)的处理(4)
  2. freemarker页面如何获取绝对路径basePath
  3. A simple script to get all pictures
  4. SVN: bdb: BDB1538 Program version 5.3 doesn't match environment version 4.7
  5. Linux内核分析——第八周学习笔记20135308
  6. MySQL 部分函数使用
  7. ubuntu14.04-rocketmq单机搭建
  8. 3527: [Zjoi2014]力 - BZOJ
  9. Leetcode#59 Spiral Matrix II
  10. Spring AOP术语
  11. 添加navbar以及上面的左右按钮代码
  12. 关于setCharacterEncoding报错
  13. I2C的读写操作实验
  14. Android开发 解决AlertDialog中的EditText无法调出输入法的问题
  15. 转 SSH框架搭建详细图文教程
  16. 传说中的华为Python笔试题——两等长整数序列互换元素,序列和的差值最小(修正)
  17. CentOS 7离线安装CDH 5.16.1完全指南(含各种错误处理)
  18. Spring再接触 自动装配
  19. ABP+AdminLTE+Bootstrap Table权限管理系统第七节--登录逻辑及几种abp封装的Javascript函数库
  20. log4j.properties 日志文件的详细配置说明

热门文章

  1. Salesforce注册教程
  2. SqlServer 用户和权限操作
  3. (转)AppCan中调用系统浏览器打开网页
  4. Python中获得当前目录和上级目录
  5. JAVA生成Word文档(经过测试)
  6. PDM生成数据库-0设置表名和字段名中不带双引号
  7. Oracle 11g oracle 用户密码过期问题 (ZT)
  8. hadoop 常用端口 及模块介绍
  9. opengl版本和扩展
  10. DAY14-前端之Bootstrap框架