//创建GDI对象
Graphics g = this.CreateGraphics();// new Graphics();

//创建画笔对象
Pen pen = new Pen(Brushes.Red);

//创建两个点
Point p1 = new Point(30, 50);
Point p2 = new Point(250, 250);
g.DrawLine(pen, p1, p2);

Graphics g = this.CreateGraphics();
g.DrawString("XX是最帅的", new Font("宋体", 20, FontStyle.Underline), Brushes.Black, new Point(300, 300));

点击更换验证码

 private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new Random();
string str = null;
for (int i = ; i < ; i++)
{
int rNumber = r.Next(, );
str += rNumber;
}
// MessageBox.Show(str);
//创建GDI对象
Bitmap bmp = new Bitmap(, );
Graphics g = Graphics.FromImage(bmp); for (int i = ; i < ; i++)
{
Point p = new Point(i * , );
string[] fonts = { "微软雅黑", "宋体", "黑体", "隶书", "仿宋" };
Color[] colors = { Color.Yellow, Color.Blue, Color.Black, Color.Red, Color.Green };
g.DrawString(str[i].ToString(), new Font(fonts[r.Next(, )], , FontStyle.Bold), new SolidBrush(colors[r.Next(, )]), p);
} for (int i = ; i < ; i++)
{
Point p1=new Point(r.Next(,bmp.Width),r.Next(,bmp.Height));
Point p2=new Point(r.Next(,bmp.Width),r.Next(,bmp.Height));
g.DrawLine(new Pen(Brushes.Green), p1, p2);
} for (int i = ; i < ; i++)
{
Point p=new Point(r.Next(,bmp.Width),r.Next(,bmp.Height));
bmp.SetPixel(p.X, p.Y, Color.Black);//设置像素
} //将图片镶嵌到PictureBox中
pictureBox1.Image = bmp;
}

GDI绘制图形的使用_验证码的更多相关文章

  1. GDI+绘制图形和画刷填充图形

    GDI+可以再Windows窗体应用程序中以编程方式绘制图形等. 可以在VS里新建项目-Windows窗体应用程序-建一个窗体.首先引入命名空间using System.Drawing.Imaging ...

  2. 戏说 .NET GDI+系列学习教程(三、Graphics类的应用_验证码扩展)

    从别人那拷贝的 #region 定义和初始化配置字段 //用户存取验证码字符串 public string validationCode = String.Empty; //生成的验证码字符串 pub ...

  3. 戏说 .NET GDI+系列学习教程(三、Graphics类的应用_验证码)

    关于Graphics也有了基本了解下面想说的的是学这个东东干什么呢,到底如何应用目前常见应用1.验证码(参照网上的)2.打印排版(会提到关于条形码大小设置)3.自定义控件 一.验证码 class Va ...

  4. 通过GDI+绘制 验证码

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

  5. C# :GDI+技术生成复杂型彩色验证码(转载)

    该类是生成一个验证码的类,集合了网上大部分的C#关于GDI+的文章进行多次改进,现在已经形成了可在生产环节中使用的验证码. 该验证码加入了背景噪点,背景噪点曲线和直线,背景噪点文字以及扭曲,调暗,模糊 ...

  6. C#GDI+ 绘制线段(实线或虚线)、矩形、字符串、圆、椭圆

    C#GDI+ 绘制线段(实线或虚线).矩形.字符串.圆.椭圆 绘制基本线条和图形 比较简单,直接看代码. Graphics graphics = e.Graphics; //绘制实线 )) { pen ...

  7. C#如何消除绘制图形缩放时抖动,总结

    一.手动双缓冲 首先定义一个BitmapBitmap backBuffer = new Bitmap(画布宽度, 画布高度);然后获取这个Bitmap的GraphicsGraphics graphic ...

  8. GDI+绘制可滚动的窗口

    在winform中绘制图形,可以使用gdi+来完成. 当绘制的图形大于目前窗口大小时,就需要滚动条来帮忙显示. 设置属性:Form.AutoScrollMinSize为要显示内容的大小. privat ...

  9. Windows App开发之编辑文本与绘制图形

    编辑文本及键盘输入 相信大家都会使用TextBox,但假设要让文本在TextBox中换行该怎么做呢?将TextWrapping属性设置为Wrap,将AcceptsReturn属性设置为True就好咯. ...

随机推荐

  1. hdfs 查看报告--命令(hdfs dfsadmin -report)

    [hadoop@master sbin]$ hdfs dfsadmin -reportConfigured Capacity: 8202977280 (7.64 GB)Present Capacity ...

  2. 构建基于虚拟用户的vsftpd服务器

    安装: [root@server ~]# yum install -y vsftpd [root@server ~]# rpm -ql vsftpd /etc/logrotate.d/vsftpd / ...

  3. Python 实现「食行生鲜」签到领积分

    用过食行生鲜的同学应该知道,每天可以在食行生鲜签到,签到可以领到 20 积分,在购物时可以抵 2 毛钱.钱虽少,但是积少成多,买菜时可以抵扣一两块钱还是不错的. 今天我们就用 Python 来实现自动 ...

  4. configured to save RDB snapshots, but is currently not able to persist o...

    Redis问题 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d ...

  5. POJ3177(无向图变双连通图)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11514   Accepted: 4946 ...

  6. MySQL锁之一:锁详解

    一.    什么是死锁 死锁是指两个或两个以上的进程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等的进 ...

  7. ubuntu 18.04 设置中文输入法

    有下面几种常用选择: IBus拼音:sudo apt-get install ibus-pinyin IBUS五笔:sudo apt-get install ibus-table-wubi 谷歌拼音输 ...

  8. appium+python 快速给真机安装app

    #coding=utf-8from appium import webdriverfrom time import sleepimport os,time,unittest '''给手机快速装app的 ...

  9. 5、scala面向对象-类

    一.类 1.定义类 ##定义并调用 scala> :paste // Entering paste mode (ctrl-D to finish) class HelloWord { priva ...

  10. Spring入门第十六课

    接上一次讲课 先看代码: package logan.spring.study.annotation.repository; public interface UserRepository { voi ...