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 ...
随机推荐
- halcon-车牌识别
halcon代码: 1: read_image(Image,'D:/MyFile/halcon/车牌识别/图片.jpg') 2: decompose3(Image,ImageR,ImageG,Imag ...
- 「小程序JAVA实战」小程序多媒体组件(27)
转自:https://idig8.com/2018/08/19/xiaochengxujavashizhanxiaochengxuduomeitizujian27/ 来说下 ,小程序的多媒体组件.源码 ...
- objective c to pas
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol ...
- iOS学习之UIPickerView控件的关联选择
接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...
- iOS开发基础控件--UILabel
UILabel 的常见属性和方法: //创建UIlabel对象 UILabel* label = [[UILabel alloc] initWithFrame:self.view.bounds]; / ...
- Linux常用命令----基本文件系统常用命令
1.查看当前工作目录---pwd sunny@sunny-ThinkPad-T450:~$ pwd /home/sunny sunny@sunny-ThinkPad-T450:~$ cd Worksp ...
- C#给图片加文字水印
public class TxtWaterMark { public enum WaterPositionMode { LeftTop,//左上 LeftBottom,//左下 RightTop,// ...
- git服务器搭建问题
CentOS6.5本地搭建. 对于图形化的系统,可以联网,然后CTRL+ALT+F2可以切换到命令行,CTRL+ALT+F1可以切换回桌面图形化. 可以用SSH和FTP来连接服务器和传文件. (1 ...
- WebSocket 教程(转载)
WebSocket 教程 作者: 阮一峰 日期: 2017年5月15日 WebSocket 是一种网络通信协议,很多高级功能都需要它. 本文介绍 WebSocket 协议的使用方法. 一.为什么需 ...
- Luogu 4238 【模板】多项式求逆
疯狂补板中. 考虑倍增实现. 假设多项式只有一个常数项,直接对它逆元就可以了. 现在假如要求$G(x)$ $$F(x)G(x) \equiv 1 (\mod x^n)$$ 而我们已经求出了$H(x)$ ...