在VS中创建窗体

(1)CDI+清除绘画面

在窗体中写入代码:

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  g.Clear(Color.Pink);

  g.Dispose();

}

(2)CGD+绘制多边形

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  Point[] points=new Point[]{

          new Point(200,200),

          new Point(230,230),

          new Point(260,300),

          new Point(300,350)

};

  g.DrawPolygon(new Pen(Color.Red),point);

  g.Dispose();

}

(3)GDI+填充颜色

protected override void OnPaint(PaintEventArgs e){

  //简单填充颜色

  Graphics g=e.Graphics;

  g.FillRectangle(Brushes.Red,new Rectangle(20,20,100,200));

  //渐变颜色填充

  Brush brush=new LinearGradientBrush(new Point(10,10),new Point(10,10),Color.Yellow,Color.White);

   g.FillRectangle(brush,new Rectangle(20,20,100,170));  

  g.Dispose();

}

(4)GDI+绘画路径

protected override void OnPaint(PaintEventArgs e){

   Graphics g = e.Graphics;
            Point[] points = new Point[]{
                 new Point(100,100),
                 new Point(100,150),
               new Point(150,200),
              new Point(50,200),
            };

  GraphicsPath path = new GraphicsPath(

      points,new byte[]{

          (byte)PathPointType.Start,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line 

      );

}

  g.DrawPath(new Pen(Color.Red),path);

  g.Dispose();

}

(4)GDI+绘制字符串

protected override void OnPaint(PaintEventArgs e){

  Graphics g = e.Graphics;

  //普通绘制字符串

  Font font1=new System.Drawing.Font("宋体",30);

  g.DrawingString("ABCD",font1,Brushes.Red,new PointF(30,30));

  //带格式的字符串

         Font font2 = new System.Drawing.Font("宋体", 30);
            RectangleF rect = new RectangleF(100,100,100,200);
            g.DrawRectangle(new Pen(Color.Red),new Rectangle(100,100,100,200));
            //字符串格式对象
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;//在矩形中居中
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString("abcd",font2,Brushes.Red,rect,sf);
            g.Dispose();

}

(5)GDI+纹理绘画图片

protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Image image = Image.FromFile("图片路径");
            //纹理画笔
            Brush brush = new TextureBrush(image);//刷出来的位置都有image的存在
            g.DrawRectangle(new Pen(Color.Pink),40,40,300,300);
            g.FillRectangle(brush,new Rectangle(40,40,300,300));
            g.Dispose();

}

GDI+的应用的更多相关文章

  1. 超全面的.NET GDI+图形图像编程教程

    本篇主题内容是.NET GDI+图形图像编程系列的教程,不要被这个滚动条吓到,为了查找方便,我没有分开写,上面加了目录了,而且很多都是源码和图片~ (*^_^*) 本人也为了学习深刻,另一方面也是为了 ...

  2. (转载)GDI+双缓冲

    双缓冲在GDI+里可以有效的提高描画效率.改善显示的质量. 下面的代码是一个最简单的双缓冲的模板.可以根据需要,做简单的修改即可. Bitmap CacheImage( [Width], [Heigh ...

  3. (转载)解决GDI闪烁

    一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化,所以不可避免在窗口移动或者改变大小的时候出现闪烁. 先来谈谈闪烁产生的原因 原因一:如果熟悉显卡原理的话,调用GDI函数向屏幕输出的 ...

  4. 通过GDI+绘制 验证码

    只为了记录下自己的学习历程,方便日后查看 现在开始言归正传,以下为其完整代码附上 using System; using System.Collections.Generic; using Syste ...

  5. 【VC++技术杂谈007】使用GDI+进行图片格式转换

    本文主要介绍如何使用GDI+对图片进行格式转换,可以转换的图片格式为bmp.jpg.png. 1.加载GDI+库 GDI+是GDI图形库的一个增强版本,提供了一系列Visual C++ API.为了使 ...

  6. C# GDI绘制矩形框,鼠标左键拖动可移动矩形框,滚轮放大缩小矩形框

    最近工作需要,要做一个矩形框,并且 用鼠标左键拖动矩形框移动其位置.网上查了一些感觉他们做的挺复杂的.我自己研究一天,做了一个比较简单的,发表出来供大家参考一下.如觉得简单,可路过,谢谢.哈哈. 先大 ...

  7. 【Windows编程】系列第五篇:GDI图形绘制

    上两篇我们学习了文本字符输出以及Unicode编写程序,知道如何用常见Win32输出文本字符串,这一篇我们来学习Windows编程中另一个非常重要的部分GDI图形绘图.Windows的GDI函数包含数 ...

  8. GDI+ 笔记

    1.GDI+模板 #include<windows.h> #include<GdiPlus.h> #include <time.h> #include <ma ...

  9. C# GDI+发生一般性错误(A generic error occurred in GDI+))

    解决思路: 1. 因为 .net GDI+ 是对底层 的封装. 所以可以尝试用 Marshal.GetLastWin32Error();函数获得底层错误代码. try{ image.Save(file ...

  10. GDI与GDI+ 贴图性能对比

    在做绘图相关工作,由于对显示绘制结果实时性有要求,筛选了GDI , 与GDI+ 贴图性能. 这里假设在内存中已绘制完成一张图片,现需求显示在控件上,同时,总是更新全部区域. GDI+ 实现 priva ...

随机推荐

  1. Oracle undo 表空间管理 (摘DAVID)

    Oracle 的Undo有两种方式: 一是使用undo 表空间,二是使用回滚段. 我们通过 undo_management 参数来控制使用哪种方式,如果设为auto,就使用UNDO 表空间,这时必须要 ...

  2. NodeJS淘宝 CNPM 镜像

    原文地址:http://npm.taobao.org/ 设置NPM镜像(前提已安装NodeJS): npm config set registry https://registry.npm.taoba ...

  3. MongoDB查询经典方式

    原文地址:http://www.cnblogs.com/stephen-liu74/archive/2012/08/03/2553803.html 1.  基本查询:    构造查询数据.    &g ...

  4. 对于一个IE8兼容性问题的反思

    近期做了一个需求,功能非常easy,把用户的优惠券数量读取出来,然后显示到"用户中心"上.开发完毕后.别的浏览器正常.可是到IE8上就不行了.并且,按下F12之后,就又能够载入出来 ...

  5. 用Darwin开发RTSP级联server(拉模式转发)(附源代码)

    源代码下载地址:https://github.com/EasyDarwin orwww.easydarwin.org 在博客 在Darwin进行实时视频转发的两种模式 中,我们描写叙述了流媒体serv ...

  6. 算法基础:整数拆分问题(Golang实现)

    一个整数总能够拆分为2的幂的和.比如: 7=1+2+4 7=1+2+2+2 7=1+1+1+4 7=1+1+1+2+2 7=1+1+1+1+1+2 7=1+1+1+1+1+1+1 总共同拥有6种不同的 ...

  7. SGU180:Inversions(树状数组)

    There are N integers (1<=N<=65537) A1, A2,.. AN (0<=Ai<=10^9). You need to find amount o ...

  8. websocket echo test

    http://www.websocket.org/echo.html .net websocket server http://superwebsocket.codeplex.com/ http:// ...

  9. Chap 2 Representing and Manipulating Information (CS:APP)

    -------------------------------------------------------------------------------------------------- A ...

  10. java中Calendar.getInstance()和new Date()的差别是什么?

    java中Calendar.getInstance()和new Date()的差别如下: Calendar.getInstance()是获取一个Calendar对象并可以进行时间的计算,时区的指定ne ...