mvc4验证码&输出图像的处理方式
/// <summary>
/// 绘制验证码
/// </summary>
/// <returns></returns>
public ActionResult VerificationCode()
{ int _verificationLength = ;
int _width = , _height = ;
SizeF _verificationTextSize;
Bitmap _bitmap = new Bitmap(Server.MapPath("~/Skins/Common/Texture.jpg"), true);
MemoryStream ms = new MemoryStream();
TextureBrush _brush = new TextureBrush(_bitmap);
//获取验证码
string _verificationText = CMS.Common.Text.VerificationText(_verificationLength);
//存储验证码
Session["VerificationCode"] = _verificationText.ToUpper();
Font _font = new Font("Arial", , FontStyle.Bold);
Bitmap _image = new Bitmap(_width, _height);
Graphics _g = Graphics.FromImage(_image);
//清空背景色
_g.Clear(Color.White);
//绘制验证码
_verificationTextSize = _g.MeasureString(_verificationText, _font);
_g.DrawString(_verificationText, _font, _brush, (_width - _verificationTextSize.Width) / , (_height - _verificationTextSize.Height) / ); _image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return File(ms.ToArray(), "image/jpeg"); }
/// <summary>
/// 获取验证码【字符串】
/// </summary>
/// <param name="Length">验证码长度【必须大于0】</param>
/// <returns></returns>
public static string VerificationText(int Length)
{
char[] _verification = new Char[Length];
Random _random = new Random();
char[] _dictionary = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '', '', '', '', '', '', '', '', '', '' };
for (int i = ; i < Length; i++)
{
_verification[i] = _dictionary[_random.Next(_dictionary.Length - )];
}
return new string(_verification);
}
mvc4验证码&输出图像的处理方式的更多相关文章
- MVC4 Action 两种异步方式
1. xxxAsync/xxxCompleted 组合方式异步,xxxCompleted 就是他的回调函数,在执行完 xxxAsync 后调用xxxCompleted . 使用 异步方式必须继承A ...
- 识别图片验证码的三种方式(scrapy模拟登陆豆瓣网)
1.通过肉眼识别,然后输入到input里面 from PIL import image Image request.urlretrieve(url,'image') #下载验证码图片 image = ...
- 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- 卷积神经网络(CNN)学习算法之----基于LeNet网络的中文验证码识别
由于公司需要进行了中文验证码的图片识别开发,最近一段时间刚忙完上线,好不容易闲下来就继上篇<基于Windows10 x64+visual Studio2013+Python2.7.12环境下的C ...
- 【转】TensorFlow练习20: 使用深度学习破解字符验证码
验证码是根据随机字符生成一幅图片,然后在图片中加入干扰象素,用户必须手动填入,防止有人利用机器人自动批量注册.灌水.发垃圾广告等等 . 验证码的作用是验证用户是真人还是机器人:设计理念是对人友好,对机 ...
- 基于LeNet网络的中文验证码识别
基于LeNet网络的中文验证码识别 由于公司需要进行了中文验证码的图片识别开发,最近一段时间刚忙完上线,好不容易闲下来就继上篇<基于Windows10 x64+visual Studio2013 ...
- ASP.NET MVC4 数据库连接(EF6.0)
我的博客原文地址:http://www.star110.com/Note/ReadArticle/60641215331146140041.html 环境:.NET MVC4 + EF6.0 连接数据 ...
- atitit.短信 验证码 破解 v3 p34 识别 绕过 系统方案规划----业务相关方案 手机验证码 .doc
atitit.短信 验证码 破解 v3 p34 识别 绕过 系统方案规划----业务相关方案 手机验证码 .doc 1. 手机短信验证码 vs 图片验证码 安全性(破解成本)确实要高一些1 1 ...
- 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
随机推荐
- ror笔记2
在rails app的 config 文件夹中新建unicorn.rb内容如下 worker_processes 2 working_directory "/home/mage/boleht ...
- 基于 DirectX11 的 MMDViewer 01-简介
这个项目主要是为了 DirectX11 而来,前面做了一个关于 OpenGL 的项目,这次打算使用 DirectX11 来做一个 MMD 的模型浏览器.以前,我使用过 DirectX11 来做过一些项 ...
- SVN 与Git的区别
1:最主要的区别是Git是分布式版本控制系统,而SVN是集中式的版本控制系统.能理解这一点,区别它们就会容易很多,Git并不是目前唯一的分布式版本控制系统,比如还有Mercurial等.不过话说回来G ...
- 【309】◀▶ Windows 相关功能实现
目录: 共享文件夹失败的解决方法 导 栅 添 1. 共享文件夹失败的解决方法 参考:解决“你没有权限访问,请与网络管理员联系” 参考:WIN7局域网文件共享设置方法 2. 导 在 3. 栅 栅 4. ...
- Ubuntu 安装 kamailio
首先安装前,你已经对kamailio的基本用法了解.可根据情况选择安装方式,本次安装基于Ubuntu18.04系统安装,对于16.04及一下会遇到版本问题,请自己查阅文档解决 安装第三方库 sudo ...
- 使用JavaScript调用aspx后台代码
方法1:js同步调用 触发: onclick="javascript:share('<%# Eval("id_File") %>')" 页面函数: ...
- python grpc
pip install grpcio pip install grpcio-tools python -m grpc_tools.protoc -I. --python_out=. --grpc_py ...
- Blending
[Blending] Blending is used to make transparent objects. When graphics are rendered, after all shade ...
- Python实现常见算法[3]——汉罗塔递归
#!/usr/bin/python # define three list var. z1 = [1,2,3,4,5,6,7,"1st zhu"] z2 = ["2st ...
- 671. Second Minimum Node In a Binary Tree 非递减二叉树中第二小的元素
[抄题]: Given a non-empty special binary tree consisting of nodes with the non-negative value, where e ...