在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. prototype 用法

    prototype使得js面向对象使用了prototype之后,使用它里面的属性或者函数 需要new出一个对象才可以使用.否则不使用prototype,直接向对象注入 function Person( ...

  2. mongoDB 高级查询之复杂查询$where

    http://blog.csdn.net/drifterj/article/details/7833883

  3. js var ImgObj=new Image();

    API地址: 1 https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement 下面来看看Image到底是个什么东东,我先将Ima ...

  4. C++ Primer Plus的若干收获--(二)

    哎,真是不想吐槽考驾照的艰辛历程了.跑到大西郊,顶着大太阳,一天就能摸上个十几分钟二十分钟的车,简直不要太坑爹,这两天真是做的我屁股疼的不行. .. 今天果断不去了.仅仅可惜我的大阿根廷啊,坚持到最后 ...

  5. C# Enum,Int,String,之间及bool与int之间的转换

    枚举类型的基类型是除 Char 外的任何整型,所以枚举类型的值是整型值. Enum 提供一些实用的静态方法: (1)比较枚举类的实例的方法 (2)将实例的值转换为其字符串表示形式的方法 (3)将数字的 ...

  6. Centos中配置环境变量

    以Java的开发环境Jdk为例. 将jdk-9.0.1放置在/usr/local下(UNIX规范),然后我们将jdk配置到环境变量中去. $ mv jdk- /usr/local $ vim /etc ...

  7. 移动端H5实现图片上传

    移动端H5实现图片上传 https://segmentfault.com/a/1190000010034177

  8. unity, 自定义类中使用print

    在unity脚本中自定义c#类,而且不继承MonoBehaviour的话,若还想在其中使用print函数,可以用MonoBehaviour.print(...).

  9. 605. Can Place Flowers【easy】

    605. Can Place Flowers[easy] Suppose you have a long flowerbed in which some of the plots are plante ...

  10. TBS 手册 --phpv 翻译

    为何使用它? 示例 下载 手册 支持 论坛 推荐 秀出你的站点 http://phpv.net/TBS_Manual.htm#html_automatic 网站: http://www.tinybut ...