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

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 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();
        }
    }