惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - g無s所p畏

vs2019(vs2017)配置菜单发布nuget包 不同应用共享redis应用,但分数据库存储数据 常用JS判断各种格式,以及替换函数等 jquery工作小笔记:jquery获取页面上控件的值 Asp.net 常用的正则表达式汇集 SCOPE_IDENTITY()代替 @@IDENTITY iis预览.net发布的网站时遇到的莫名问题:无资源行。 sql 自动补位 将公历转换成农历的类_C# 数字人民币(RMB)转化为大写字母 2007年工作总结 .NET中AJAX乱码问题解决 图片无缝滚动 千万级通用的分页存储过程 求助:C#读取邮件 求助:一个能够验证到时、分甚至秒的脚本表达式 SQL中触发器实例讲解 SQL中CONVERT转化函数的用法 获取远程服务器的ip地址以及地区地址
生成验证码图片(含模糊背景)
g無s所p畏 · 2007-04-07 · via 博客园 - g無s所p畏

首先可以传来一个strCode,这个可以用简单的脚本生成就可以了
function buildImgCode()
    {
        vImgCode=Math.random().toString(10).substring(2,6);
        document.getElementById("imgCode").src="生成图片的页面.aspx?c="+vImgCode;
    } 

生成图片的页面:
this.buildCodeImg(this.Request["c"]);
private void buildCodeImg(string strCode)
    {
        if(strCode==null||strCode.Trim()==String.Empty||strCode=="")
            return;

        System.Drawing.Bitmap image=new System.Drawing.Bitmap((int)Math.Ceiling((strCode.Length*12.5)),22);
        Graphics g=Graphics.FromImage(image);

        try
        {
            //生成随机生成器
            Random random=new Random();

            //清空图片背景色
            g.Clear(Color.White);

            //画图片的背景噪音线
            for(int i=0;i<25;i++)
            {
                int x1=random.Next(image.Width);
                int x2=random.Next(image.Width);
                int y1=random.Next(image.Height);
                int y2=random.Next(image.Height);

                g.DrawLine(new Pen(Color.Silver),x1,y1,x2,y2);
            }

            Font font=new System.Drawing.Font("Arial",12,(System.Drawing.FontStyle.Bold|System.Drawing.FontStyle.Italic));
            System.Drawing.Drawing2D.LinearGradientBrush brush=new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0,0,image.Width,image.Height),Color.Blue,Color.DarkRed,1.2f,true);
            g.DrawString(strCode,font,brush,2,2);

            //画图片的前景噪音点
            for(int i=0;i<100;i++)
            {
                int x=random.Next(image.Width);
                int y=random.Next(image.Height);

                image.SetPixel(x,y,Color.FromArgb(random.Next()));
            }

            //画图片的边框线
            g.DrawRectangle(new Pen(Color.Silver),0,0,image.Width-1,image.Height-1);

            System.IO.MemoryStream ms=new System.IO.MemoryStream();
            image.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            Response.ContentType="image/Gif";
            Response.BinaryWrite(ms.ToArray());
        }
        finally
        {
            g.Dispose();
            image.Dispose();
        }
    }