ChaosSea验证码0.20版

ChaosSea验证码0.20版

功能说明:
1. 可自定义字体
2. 可自定义最大字号
3. 可自定义随机旋转的角度
4. 可自定义前景随机噪色量
5. 可外部生成随机码,由VerifyCode类处理成图片
6. 可自定义数字与英文字母随机出现的比率
7. 可自定义验证码长度
8. 可自定义验证码背景色
9. 可自定义验证码色彩(噪点色同验证码色一致)
10. 可自定义字体

------------------------------
本人觉得用上随机角度就行了,不用前景噪点,因为这个东东会耗一定的资源

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;
using System.Drawing;


namespace CS.Common.Utility
{
    
/// <summary>
    
/// Chaos验证码
    
/// FileName            :    VerifyCode.cs   
    
/// Verion             :       0.20
    
/// Author             :       zhouyu  http://max.cszi.com
    
/// Update            :       2007-10-10
    
/// Description      :       验证码随机旋转一定角度,可使用前景色,背景色效果不大就不用了
    
/// </summary>

    public class VerifyCode
    
{

        
private int _length = 4;            //验证码长度
        private int _fontSize = 18;       //字体最大尺寸
        private int _border = 0;           //边框,0时没有连框
        private Color _backgroundColor = Color.AliceBlue;   //背景色
        private Color _fontColor = Color.Blue;     //验证码色
        private int _rateNumber = 10;       //验证码中的数字出现机率 ,越大出现的数字机率越大
        private string _randomChars;       //随机生成的验证码
        private int _randomAngle = 40;       //随机码的旋转角度
        private string _fontFamily = "Verdana";    //字体
        private int _chaosNumber = 0;        //噪点数量 ,0 时不用

        
private Random random = new Random();  //随机种子,公用

        
public VerifyCode()
        
{
           
        }


        
/// <summary>
        
/// 重载一 :噪点
        
/// </summary>
        
/// <param name="chaosNumber"></param>

        public VerifyCode(int chaosNumber)
        
{
            _chaosNumber 
= chaosNumber;
        }


        
/// <summary>
        
/// 重载二:长度,噪点
        
/// </summary>
        
/// <param name="length"></param>
        
/// <param name="chaosNumber"></param>

        public VerifyCode(int length, int chaosNumber)
        
{
            _length 
= length;
            _chaosNumber 
= chaosNumber;
        }


        
/// <summary>
        
/// 重载三:长度,噪点,数字机率
        
/// </summary>
        
/// <param name="length"></param>
        
/// <param name="chaosNumber"></param>
        
/// <param name="rate">越大,生成的随机码中数字占的比例越多</param>

        public VerifyCode(int length, int chaosNumber, int rate)
        
{
            _length 
= length;
            _chaosNumber 
= chaosNumber;
            _rateNumber 
= rate;
        }



        
.Length 验证码长度(默认4个) 

        
.FontSize 字体最大尺寸(默认18) 

        
.Border 边框(默认0 没有连框)

        
.BackgroundColor 自定义背景色(默认Color.AliceBlue)

        
.FontColor 验证码色(默认Color.Blue)

        
.RandomCode  随机生成的验证码

        
.RateNumber 验证码中的数字出现机率,越大出现的数字机率越大(默认10)

        
.RandomAngle 随机码的旋转角度(默认40度)

        
.FontFamily 字体

        
.ChaosNumber 噪点数量(默认值为2)





        
/// <summary>
        
/// 生成随机验证码
        
/// </summary>

        private void CreateCode()
        
{
            
//有外部输入验证码时不用产生,否则随机生成
            if (!string.IsNullOrEmpty(_randomChars))
            
return; }

            
char code;
            
for (int i = 0; i < _length; i++)
            
{
                
int rand = random.Next();
                
if (rand % _rateNumber == 0)
                
{ code = (char)('A' + (char)(rand % 26)); }
                
else
                
{ code = (char)('0' + (char)(rand % 10)); }
                _randomChars 
+= code.ToString();
            }

        }




        
/// <summary>
        
/// 背景噪点生成
        
/// </summary>
        
/// <param name="graph"></param>

        private void  CreateBackgroundChaos(Bitmap map,Graphics graph)
        
{
            Pen blackPen 
= new Pen(Color.Azure, 0);
            
for (int i = 0; i < map.Width * 2; i++)
            
{
                
int x = random.Next(map.Width);
                
int y = random.Next(map.Height);
                graph.DrawRectangle(blackPen, x, y, 
11);
            }

        }


        
/// <summary>
        
/// 前景色噪点
        
/// </summary>
        
/// <param name="map"></param>

        private void CreaetForeChaos(Bitmap map)
        
{
            
for (int i = 0; i < map.Width * _chaosNumber; i++)
            
{
                
int x = random.Next(map.Width);
                
int y = random.Next(map.Height);
                
//map.SetPixel(x, y, Color.FromArgb(random.Next(300)));
                map.SetPixel(x, y, _fontColor);
            }

        }



        
/// <summary>
        
/// 创建随机码图片
        
/// </summary>
        
/// <param name="context"></param>

        public void CreateImage(HttpContext context)
        
{
            CreateCode();     
//创建验证码

            Bitmap map 
= new Bitmap((int)(_randomChars.Length * 15), 24);              //创建图片背景
            Graphics graph = Graphics.FromImage(map);
            
//graph.FillRectangle(new SolidBrush(Color.Black), 0, 0, map.Width+1, map.Height+1);     //填充一个有背景的矩形
            
            
//if (_border > 0) //画一个边框
            
//{
            
//    graph.DrawRectangle(new Pen(Color.Black, 0), 0, 0, map.Width - _border, map.Height - _border);
            
//}    
            
//graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;    //模式

            graph.Clear(_backgroundColor);       
//清除画面,填充背景
            SolidBrush brush = new SolidBrush(_fontColor);  //画笔
            Point dot = new Point(1212);

            
//CreateBackgroundChaos(map,graph);       //背景噪点生成

            CreaetForeChaos(map);       
//前景色噪点

            
//文字距中
            StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            format.Alignment 
= StringAlignment.Center;
            format.LineAlignment 
= StringAlignment.Center;

            
//验证码旋转,防止机器识别
            char[] chars = _randomChars.ToCharArray();      //拆散字符串成单字符数组
            for (int i = 0; i < chars.Length; i++)
            
{
                Font fontstyle 
= new Font(_fontFamily, random.Next(_fontSize - 3, _fontSize), FontStyle.Regular);      //字体样式
                float angle = random.Next(-_randomAngle, _randomAngle);      //转动的度数

                graph.TranslateTransform(dot.X, dot.Y);     
//移动光标到指定位置
                graph.RotateTransform(angle);
                graph.DrawString(chars[i].ToString(), fontstyle, brush, 
-22, format);
                graph.RotateTransform(
-angle);          //转回去
                graph.TranslateTransform(2-dot.Y);     //移动光标到指定位置
            }

           

            
//生成图片
            MemoryStream ms = new MemoryStream();
            map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            context.Response.ClearContent();
            context.Response.ContentType 
= "image/gif";
            context.Response.BinaryWrite(ms.ToArray());
            graph.Dispose();
            map.Dispose();

        }










    }






}

 

 使用方法:

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CS.Common.Utility;

namespace Test
{
    
public partial class Vcode : System.Web.UI.Page
    
{
        
protected void Page_Load(object sender, EventArgs e)
        
{

            VerifyCode vcode 
= new VerifyCode();

            vcode.CreateImage(
base.Context);

            Session[
"VerifyCode"= vcode.RandomCode;

          

        }

    }

}

 

把这个页面当成图片引用就行了!

 

内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
内容概要:本文档介绍了一种基于ADP5070 DC-DC开关稳压器、ADP7142和ADP7182 CMOS LDO线性稳压器、LC滤波器及电阻分压器的电路设计方案,旨在为仅拥有5 V单电源的系统提供低噪声、双电源解决方案,以支持AD5761R双极性DAC的工作。AD5761R是一款16位双极性DAC,需要双电源来提供双极性输出电压范围。文中详细描述了如何配置该电路以适应单电源系统的应用,并展示了不同电源配置(包括外部电源、ADP5070和LC滤波器、ADP5070和LDO线性稳压器)下的性能测试结果,特别是频谱分析、输出电压噪声和交流性能等方面的数据。测试结果表明,增加LDO线性稳压器可以显著降低输出噪声,提升整体性能。 适合人群:从事精密仪器设计、数据采集系统开发的技术人员,尤其是那些需要理解和应用低噪声电源解决方案的专业人士。 使用场景及目标:适用于需要从单一5 V电源生成双电源的应用场合,如测试与测量设备、数据采集系统、执行器控制系统和工业自动化等领域。主要目标是在保证低噪声的前提下,确保AD5761R DAC能够在单电源环境中正常工作,提供高质量的双极性输出。 其他说明:本文档不仅提供了详细的电路配置指南,还通过大量的图表和数据分析验证了不同电源配置的效果。特别强调了在不同频率范围内,使用内部基准电压源和外部基准电压源(如ADR4525)对DAC输出噪声的影响。此外,文档还讨论了LC滤波器和LDO线性稳压器在减少开关纹波方面的作用,为实际应用提供了有价值的参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值