使用GDI验证码
来源:互联网 发布:网络课程plc网络教育 编辑:程序博客网 时间:2024/05/18 23:14
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 使用GDI验证码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 点击更换验证码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new Random();
string str = null;
for (int i = 0; i < 5; i++)
{
int rNumber = r.Next(0, 10);
str += rNumber;
}
//MessageBox .Show (str);
//创建GDI对象
Bitmap bmp = new Bitmap(150, 40);
Graphics g = Graphics.FromImage(bmp);
//将图片镶嵌到PictureBox中
for (int i= 0;i <5; i++)
{
Point p=new Point (i*20,0);
string[] fonts = { "微软雅黑", "宋体", "黑体", "隶书", "仿宋" };
Color[] colors = { Color.Yellow, Color.Blue, Color.Black, Color.Red, Color.Green };
g.DrawString (str[i].ToString (), new Font(fonts[r.Next (0,5)], 20, FontStyle.Bold ), new SolidBrush (colors[r.Next( 0,5)]),p);
}
for (int i = 0; i <20; i++)
{
Point p1=new Point (r.Next (0,bmp.Width ),r.Next (0,bmp.Height));
Point p2=new Point (r.Next (0,bmp.Width ),r.Next (0,bmp.Height ));
g.DrawLine (new Pen(Brushes.Green),p1,p2);
}
for (int i = 0; i < 10; i++)
{
Point p=new Point (r.Next (0,bmp.Width),r.Next (0,bmp.Height ));
bmp.SetPixel (p.X,p.Y,Color.Black);
}
pictureBox1.Image = bmp;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 使用GDI验证码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 点击更换验证码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new Random();
string str = null;
for (int i = 0; i < 5; i++)
{
int rNumber = r.Next(0, 10);
str += rNumber;
}
//MessageBox .Show (str);
//创建GDI对象
Bitmap bmp = new Bitmap(150, 40);
Graphics g = Graphics.FromImage(bmp);
//将图片镶嵌到PictureBox中
for (int i= 0;i <5; i++)
{
Point p=new Point (i*20,0);
string[] fonts = { "微软雅黑", "宋体", "黑体", "隶书", "仿宋" };
Color[] colors = { Color.Yellow, Color.Blue, Color.Black, Color.Red, Color.Green };
g.DrawString (str[i].ToString (), new Font(fonts[r.Next (0,5)], 20, FontStyle.Bold ), new SolidBrush (colors[r.Next( 0,5)]),p);
}
for (int i = 0; i <20; i++)
{
Point p1=new Point (r.Next (0,bmp.Width ),r.Next (0,bmp.Height));
Point p2=new Point (r.Next (0,bmp.Width ),r.Next (0,bmp.Height ));
g.DrawLine (new Pen(Brushes.Green),p1,p2);
}
for (int i = 0; i < 10; i++)
{
Point p=new Point (r.Next (0,bmp.Width),r.Next (0,bmp.Height ));
bmp.SetPixel (p.X,p.Y,Color.Black);
}
pictureBox1.Image = bmp;
}
}
}
阅读全文
0 0
- 使用GDI验证码
- 使用GDI+绘制验证码
- 使用GDI绘制验证码
- 使用GDI绘制验证码
- 使用GDI绘制验证码
- C#中使用GDI绘制验证码
- GDI+在绘制验证码中的使用
- c# 使用GDI绘制验证码实例
- GDI+图形验证码
- GDI+验证码实现
- GDI+绘制验证码
- GDI+之验证码
- 使用GDI+识别简单的图形验证码
- 用GDI+制作验证码!!!
- 利用GDI+绘制验证码
- C#中GDI绘图和GDI绘制随即验证码
- GDI制作验证码cs代码
- Asp.net中GDI+生成验证码
- Java读取大文件的高效率实现
- em和rem的理解
- 2.网络入侵方法及IPS产品防护能力测试方法
- Jsoup基本使用
- python3.4的安装方法
- 使用GDI验证码
- 路由器
- PAT1103
- 静态链表
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- modelsim仿真一直卡在loading之解决办法
- IDL中自定义过程与函数关键字参数说明
- Monte Carlo随机模拟
- linux内核调试技巧 dump_stack()