void CodeImage(string code)
{
if (code == null || code.Trim() == string.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling(code.Length * 11.0), );
Graphics g = Graphics.FromImage(image);
try
{
Random rdm = new Random();
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = ; i < ; i++)
{
int x1 = rdm.Next(image.Width);
int x2 = rdm.Next(image.Width);
int y1 = rdm.Next(image.Height);
int y2 = rdm.Next(image.Height);
g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", , FontStyle.Bold);
g.DrawString(code, font, new SolidBrush(Color.Red), , );
//画前景噪音线
for (int i = ; i < ; i++)
{
int x = rdm.Next(image.Width);
int y = rdm.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(rdm.Next()));
}
g.DrawRectangle(new Pen(Color.Silver), , , image.Width - , image.Height - );
pictureBox1.Width = image.Width;
pictureBox1.Height = image.Height;
pictureBox1.Image = image;
}
catch
{ }
}

C#制作验证码的更多相关文章

  1. (一)学习MVC之制作验证码

    制作验证码的方法在@洞庭夕照 看到的,原文链接:http://www.cnblogs.com/mzwhj/archive/2012/10/22/2720089.html 现自己利用该方法制作一个简单的 ...

  2. Jsp制作验证码

    验证码 验证码(CAPTCHA)是"Completely Automated Public Turing test to tell Computers and Humans Apart&qu ...

  3. php 制作验证码不显示的问题

    php制作验证码的代码,这里就不多说了,网上有很多的,这里说一些可能遇到的问题. 1. 首先是检查自己的php.ini文件,是否支持gd库. 2.保证代码没有出问题. 3.检查字体文件路径是否正确. ...

  4. java制作验证码(java验证码小程序)

    手动制作java的验证码 Web应用验证码的组成: (1)输入框 (2)显示验证码的图片 验证码的制作流程: 生成验证码的容器使用 j2ee的servlet 生成图片需要的类: (1) Buffere ...

  5. 使用python制作验证码

    方法一 简单型:使用random模块制作一个随机字母与数字的验证码 import random def make_code(n): res='' for i in range(n): num=str( ...

  6. 在ashx文件中制作验证码(使用session要继承IRequiresSessionState)

    必须继承System.Web.SessionState.IRequiresSessionState接口,才能实现Session读写! System.Web.SessionState的一些接口 IRea ...

  7. jcaptcha sample 制作验证码

    Skip to end of metadata Created by marc antoine garrigue, last modified by Jeremy Waters on Feb 23, ...

  8. java制作验证码

    建立一个web工程

  9. 怎样用PHP制作验证码呢?

    生成验证码无非就那么几个步骤,首先是获取一个随机字符串,然后创建一个布画,将生成的字符串写到布画上,我们还可以在布画上画线画雪花,现在帖一段生成验证码的代码. 源代码: <?phpsession ...

  10. DAY19-Pillow制作验证码

    PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...

随机推荐

  1. intellij idea 高级用法之:集成JIRA、UML类图插件、集成SSH、集成FTP、Database管理

    之前写过一篇IntelliJ IDEA 13试用手记,idea还有很多高大上的功能,易用性几乎能与vs.net媲美,反正我自从改用idea后,再也没开过eclipse,今天来看几个高级功能: 一.与J ...

  2. 什么是API

    我们从API的功能.分类.设计.实现.用户来看什么是API. API是应用程序组件之间通信的接口 --wiki:Application Programming Interface In compute ...

  3. .NET平台下的微信SDK(Rabbit.WeiXin)开源发布

    在上一篇文章<RabbitHub开源情况及计划>上有提及到了一个新的开源项目——微信SDK,经过几天的努力现在开源发布Beta1版本. 目录 前言 特点 功能 支持的消息类型 请求消息 事 ...

  4. Ryu

    What's Ryu? Ryu is a component-based software defined networking framework. Ryu provides software co ...

  5. 遍历Arraylist的方法:

    遍历Arraylist的几种方法: Iterator it1 = list.iterator();        while(it1.hasNext()){            System.out ...

  6. 分析函数——keep(dense_rank first/last)

    来源于:http://blog.itpub.net/28929558/viewspace-1182183/ 销售表:SQL> select * from criss_sales where de ...

  7. [Bundling and Minification ] 一、如何绑定

    绑定和压缩(缩小)是ASP.NET 4.5出现的用来提高程序性能的两个重要的技术.绑定(Bundling)是将多个文件合并为一个文件,压缩(Minification)主要是将文件缩小,如Js .CSS ...

  8. HttpServletRequest 转换成MultipartHttpServletRequest

    //转换 HttpServletRequestMultipartHttpServletRequest mulReq=(MultipartHttpServletRequest)request;//获取上 ...

  9. iOS开发中的错误整理,再一次整理通过通知中心来处理键盘,一定记得最后关闭通知中心

    一.打开通知中心,监听键盘的显示与隐藏 二.最后记得将监听通知的对象移除

  10. git将本地代码 和服务器git@osc 上的代码 关联

    将本地代码 和服务器git@osc 上的代码 关联 要使用git 首先,你得安装一个git 下载 http://git-scm.com/downloads 安装完成后,需要简单的配置一下,打开 Git ...