博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
验证码 生成变形的文字
阅读量:6266 次
发布时间:2019-06-22

本文共 3206 字,大约阅读时间需要 10 分钟。

None.gif
using
 System;
None.gif
using
 System.IO;
None.gif
using
 System.Web;
None.gif
using
 System.Web.UI;
None.gif
using
 System.Drawing;
None.gif
using
 System.Drawing.Drawing2D;
None.gif
using
 System.Drawing.Imaging;
None.gif
namespace
 Mis.Pages
ExpandedBlockStart.gif
{
InBlock.gif    
public class think_test:System.Web.UI.Page
ExpandedSubBlockStart.gif    
{
InBlock.gif        
protected System.Web.UI.WebControls.TextBox TextBox1;
InBlock.gif        
protected System.Web.UI.WebControls.Button Button1;
InBlock.gif        
private Random rand = new Random();
InBlock.gif        
protected override void OnInit(EventArgs e)
ExpandedSubBlockStart.gif        
{    
InBlock.gif            
base.OnInit(e);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
ExpandedSubBlockEnd.gif        }
InBlock.gif        
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gif        
{
InBlock.gif            
string checkCode = CreateRandomCode(8);
InBlock.gif            Session[
"CheckCode"= checkCode;
InBlock.gif            CreateImage(checkCode);
ExpandedSubBlockEnd.gif        }
InBlock.gif
ContractedSubBlock.gif        
Web 窗体设计器生成的代码
InBlock.gif
InBlock.gif        
InBlock.gif        
private string CreateRandomCode(int codeCount)
ExpandedSubBlockStart.gif        
{
InBlock.gif            
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z" ;
InBlock.gif            
string[] allCharArray = allChar.Split(',');
InBlock.gif            
string randomCode = "";
InBlock.gif            
int temp = -1;
InBlock.gif            
for(int i = 0; i < codeCount; i++)
ExpandedSubBlockStart.gif            
{
InBlock.gif                
if(temp != -1)
ExpandedSubBlockStart.gif                
{
InBlock.gif                    rand 
= new Random(i*temp*((int)DateTime.Now.Ticks));
ExpandedSubBlockEnd.gif                }
InBlock.gif                
int t = rand.Next(35);
InBlock.gif                
if(temp == t)
ExpandedSubBlockStart.gif                
{
InBlock.gif                    
return CreateRandomCode(codeCount);
ExpandedSubBlockEnd.gif                }
InBlock.gif                temp 
= t;
InBlock.gif                randomCode 
+= allCharArray[t];
ExpandedSubBlockEnd.gif            }
InBlock.gif            
return randomCode;
ExpandedSubBlockEnd.gif        }
InBlock.gif        
InBlock.gif        
private void TransformG(Graphics g)
ExpandedSubBlockStart.gif        
{
InBlock.gif            Matrix myMatrix 
= new Matrix();
InBlock.gif            
int num1=rand.Next(80,900);
InBlock.gif            
int num2=rand.Next(80,800);
InBlock.gif            
float dd1=(float)num1;
InBlock.gif            
float dd2=(float)num2;
InBlock.gif            dd1
=dd1/10000;
InBlock.gif            dd2
=dd2/10000;
InBlock.gif            
float f1 = (float)(dd1);
InBlock.gif            
float f2 = (float)(dd2);
InBlock.gif            myMatrix.Shear(f1,f2);
InBlock.gif            g.MultiplyTransform(myMatrix);
ExpandedSubBlockEnd.gif        }
InBlock.gif        
InBlock.gif        
private void CreateImage(string checkCode)
ExpandedSubBlockStart.gif        
{
InBlock.gif            
int iwidth = (int)(checkCode.Length * 11.5);
InBlock.gif            System.Drawing.Bitmap image 
= new System.Drawing.Bitmap(15046);
InBlock.gif            Graphics g 
= Graphics.FromImage(image);
InBlock.gif            g.SmoothingMode
=SmoothingMode.HighQuality;
InBlock.gif            Font f 
= new System.Drawing.Font("Arial"18, System.Drawing.FontStyle.Regular);
InBlock.gif            Brush b 
= new System.Drawing.SolidBrush(Color.LightSlateGray);
InBlock.gif            Rectangle rect 
= new Rectangle(0015046);
InBlock.gif            HatchBrush hatchBrush 
= new HatchBrush(
InBlock.gif                HatchStyle.SmallConfetti,
InBlock.gif                Color.LightGray,
InBlock.gif                Color.White);
InBlock.gif            g.FillRectangle(hatchBrush, rect);
ExpandedSubBlockStart.gif            Point[] myArray 
={
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46)),
InBlock.gif                                 
new Point(rand.Next(150),rand.Next(46))
ExpandedSubBlockEnd.gif                             }
;
InBlock.gif            Pen myPen 
= new Pen(Color.Blue,1);
InBlock.gif
InBlock.gif            GraphicsPath myPath 
= new GraphicsPath();
InBlock.gif            myPath.AddBeziers(myArray);
InBlock.gif            g.DrawPath(myPen, myPath);
InBlock.gif
InBlock.gif            SizeF size;
InBlock.gif            
float CPostion=1;
InBlock.gif            
for(int i=0;i<checkCode.Length;i++)
ExpandedSubBlockStart.gif            
{
InBlock.gif                TransformG(g);
InBlock.gif                size 
= g.MeasureString(checkCode[i].ToString(), f);
InBlock.gif                g.DrawString(checkCode[i].ToString(), f, b, CPostion, 
7);
InBlock.gif                CPostion
+=size.Width-1;
InBlock.gif                g.ResetTransform();
ExpandedSubBlockEnd.gif            }
InBlock.gif
InBlock.gif            System.IO.MemoryStream ms 
= new System.IO.MemoryStream();
InBlock.gif            image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
InBlock.gif            g.Dispose();
InBlock.gif            image.Dispose();
InBlock.gif            Response.ClearContent();
InBlock.gif            Response.ContentType 
= "image/Jpeg";
InBlock.gif            Response.BinaryWrite(ms.ToArray());
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        
private void Button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gif        
{
InBlock.gif        
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    }
    
ExpandedBlockEnd.gif}
本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/12/253059.html,如需转载请自行联系原作者
你可能感兴趣的文章
hadoop、hbase、zookeeper集群搭建
查看>>
python中一切皆对象------类的基础(五)
查看>>
modprobe
查看>>
android中用ExpandableListView实现三级扩展列表
查看>>
%Error opening tftp://255.255.255.255/cisconet.cfg
查看>>
java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
查看>>
《从零开始学Swift》学习笔记(Day 51)——扩展构造函数
查看>>
python多线程队列安全
查看>>
[汇编语言学习笔记][第四章第一个程序的编写]
查看>>
android 打开各种文件(setDataAndType)转:
查看>>
补交:最最原始的第一次作业(当时没有选上课,所以不知道)
查看>>
Vue实例初始化的选项配置对象详解
查看>>
PLM产品技术的发展趋势 来源:e-works 作者:清软英泰 党伟升 罗先海 耿坤瑛
查看>>
vue part3.3 小案例ajax (axios) 及页面异步显示
查看>>
软件测试(二)之 Failure, Error & Fault
查看>>
浅谈MVC3自定义分页
查看>>
.net中ashx文件有什么用?功能有那些,一般用在什么情况下?
查看>>
select、poll、epoll之间的区别总结[整理]【转】
查看>>
CSS基础知识(上)
查看>>
PHP中常见的面试题2(附答案)
查看>>