根据jeff377 的话,竹子将这验证码改进了一下,请大家讨论看看。
-------jeff377--------------------------------------------
我研究所的论文就是在做类神经网络处理文字辨识,以你的例子而言,旋转随意角度对辨识来说并不会有太大影响,只要抓字的重心,360度旋转抓取特微值,还是可以辨识的出来。
通常文字辨识的有一个重要的动作,就是要把个别文字分割,你只要把文字弄的难分割就有不错的安全性。
---------------------------------------------------

代码比较粗糙,而且比较菜,其中遇到一个问题,未对 Graphics 填充底色,那么文字的 ClearType 效果没有了,文字毛边比较明显,不知道为什么,谁能告诉竹子?

代码相对粗糙,没有考虑更多的情况,在测试过程中,以20px 字体呈现,效果感觉还不错,只是 ClearType 效果没有了。

帖几张看看

------------

------------

------------

------------
有一些随机的不好,象下面这张

相关链接:
查看 V1.0

.NET 2.0 代码如下:

using System;
using System.Drawing;
using System.Web;

namespace Oran.Image
{
    /// <summary>
    /// 旋转的可视验证码图象
    /// </summary>
    public class RotatedVlidationCode
    {
        public enum RandomStringMode
        {
            /// <summary>
            /// 小写字母
            /// </summary>
            LowerLetter,
            /// <summary>
            /// 大写字母
            /// </summary>
            UpperLetter,
            /// <summary>
            /// 混合大小写字母
            /// </summary>
            Letter,
            /// <summary>
            /// 数字
            /// </summary>
            Digital,
            /// <summary>
            /// 混合数字与大小字母
            /// </summary>
            Mix
        }

public static string GenerateRandomString(int length, RandomStringMode mode)
        {
            string rndStr = string.Empty;
            if (length == 0)
                return rndStr;

//以数组方式候选字符,可以更方便的剔除不要的字符,如数字 0 与字母 o
            char[] digitals = new char[10] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            char[] lowerLetters = new char[26] {
                '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' };
            char[] upperLetters = new char[26] {
                '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' };
            char[] letters = new char[52]{
                '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' };
            char[] mix = new char[62]{
                '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', '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' };

int[] range = new int[2] { 0, 0 };
            Random random = new Random();

switch (mode)
            {
                case RandomStringMode.Digital:
                    for (int i = 0; i < length; ++i)
                        rndStr += digitals[random.Next(0, digitals.Length)];
                    break;

case RandomStringMode.LowerLetter:
                    for (int i = 0; i < length; ++i)
                        rndStr += lowerLetters[random.Next(0, lowerLetters.Length)];
                    break;

case RandomStringMode.UpperLetter:
                    for (int i = 0; i < length; ++i)
                        rndStr += upperLetters[random.Next(0, upperLetters.Length)];
                    break;

case RandomStringMode.Letter:
                    for (int i = 0; i < length; ++i)
                        rndStr += letters[random.Next(0, letters.Length)];
                    break;

default:
                    for (int i = 0; i < length; ++i)
                        rndStr += mix[random.Next(0, mix.Length)];
                    break;
            }

return rndStr;
        }

/// <summary>
        /// 显示验证码
        /// </summary>
        /// <param name="seed">随机数辅助种子</param>
        /// <param name="strLen">验证码字符长度</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="mode">随机字符模式</param>
        /// <param name="clrFont">字体颜色</param>
        /// <param name="clrBg">背景颜色</param>
        public static void ShowValidationCode(ref int seed, int strLen, int fontSize, RandomStringMode mode, Color clrFont, Color clrBg)
        {
            int tmpSeed;
            unchecked
            {
                tmpSeed = (int)(seed * DateTime.Now.Ticks);
                ++seed;
            }
            Random rnd = new Random(tmpSeed);

string text = GenerateRandomString(strLen, mode);
            int height = fontSize * 2;
            // 因为字体旋转后每个字体所占宽度会所有加大,所以要加一点补偿宽度
            int width = fontSize * text.Length + fontSize / (text.Length - 2);
            Bitmap bmp = new Bitmap(width, height);

Graphics graphics = Graphics.FromImage(bmp);
            Font font = new Font("Courier New", fontSize, FontStyle.Bold);
            Brush brush = new SolidBrush(clrFont);
            Brush brushBg = new SolidBrush(clrBg);
            graphics.FillRectangle(brushBg, 0, 0, width, height);
            Bitmap tmpBmp = new Bitmap(height, height);
            Graphics tmpGph = null;
            int degree = 40;
            Point tmpPoint = new Point();
            for (int i = 0; i < text.Length; i++)
            {
                tmpBmp = new Bitmap(height, height);
                tmpGph = Graphics.FromImage(tmpBmp);
               // tmpGph.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
               // 不填充底色,文字 ClearType 效果不见了,why?!
               // tmpGph.FillRectangle(brushBg, 0, 0, tmpBmp.Width, tmpBmp.Height);
                degree = rnd.Next(20, 51); // [20, 50]随机角度
                if (rnd.Next(0, 2) == 0)
                {
                    tmpPoint.X = 12; // 调整文本坐标以适应旋转后的图象
                    tmpPoint.Y = -6;
                }
                else
                {
                    degree = ~degree + 1; // 逆时针旋转
                    tmpPoint.X = -10;
                    tmpPoint.Y = 6;
                }

tmpGph.RotateTransform(degree);
                tmpGph.DrawString(text[i].ToString(), font, brush, tmpPoint);
                graphics.DrawImage(tmpBmp, i * fontSize, 0); // 拼接图象
            }
            
            //输出图象
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            bmp.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif);
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ContentType = "image/gif";
            HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
            HttpContext.Current.Response.End();

//释放资源
            font.Dispose();
            brush.Dispose();
            brushBg.Dispose();
            tmpGph.Dispose();
            tmpBmp.Dispose();
            graphics.Dispose();
            bmp.Dispose();
            memoryStream.Dispose();
        }
    }
}

转载于:https://www.cnblogs.com/iRed/archive/2008/06/22/1227687.html

每个字符旋转随机角度的图象验证码 V2.0相关推荐

  1. matlab控制三角形绕原点旋转任意角度

    项目中遇到一个问题,需要把正三角形绕原点旋转任意角度,平时操作图片的时候,顺便旋转,感觉好像很简单,但是自己去做的时候还是有些困难. 我觉得旋转的难点在于由原始点计算新的目标点上,因为你需要考虑点位于 ...

  2. 旋转Apriltag角度检测

    简 介: 从实验角度介绍了Apriltag的角度检测,与Apriltag张贴方向有关系,与摄像头内参设定也有关系.通过旋转Apriltag码方向检测验证了算法的鲁棒性. 关键词: Apriltag,单 ...

  3. C# 使用 GDI+ 实现添加中心旋转(任意角度)的文字

    这篇文章是 GDI+ 总结系列的第三篇,如果对 GDI+ 的基础使用不熟悉的朋友可以先看第一篇文章<C# 使用 GDI+ 画图>. 需求 需求是要实现给图片添加任意角度旋转的文字,文字的旋 ...

  4. Qt绘制旋转的轮播图

    前言 目前见的比较多的轮播图有平移和旋转两种方式.平移类似淘宝那种切换幻灯片一样的效果,旋转一般是近大远小,看起来有点3D的感觉.本文代码实现旋转轮播图效果如下: 完整代码链接: https://gi ...

  5. python使用matplotlib可视化、自定义Y轴轴标签刻度旋转的角度(customize degree rotating axis tick labels in matplotlib)

    python使用matplotlib可视化.自定义Y轴轴标签刻度旋转的角度(customize degree rotating axis tick labels in matplotlib y aix ...

  6. R语言ggplot2可视化轴标签重叠问题解决实战:修改轴标签字体、轴标签垂直于坐标轴(或者旋转特定角度)

    R语言ggplot2可视化轴标签重叠问题解决实战:修改轴标签字体.轴标签垂直于坐标轴(或者旋转特定角度) 目录

  7. iOS开发 CGAffineTransform 让图片旋转, 旋转后获得图片旋转的角度

    1.让图片旋转 UIImageView *imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(50, 50, 200 ...

  8. Python+tkinter模拟京东旋转图片式验证码输入

    好消息:"Python小屋"编程比赛正式开始 推荐图书: <Python程序设计(第3版)>,(ISBN:978-7-302-55083-9),董付国,清华大学出版社, ...

  9. JQuery插件让图片旋转任意角度且代码极其简单 - 摘自网友

    JQuery插件让图片旋转任意角度且代码极其简单 2012-04-01 09:57:03     我来说两句       收藏    我要投稿 引入下方的jquery.rotate.js文件,然后通过 ...

  10. C# 计算一点绕另一点旋转一定角度后新点的坐标

    计算一点绕另一点旋转一定角度后新点的坐标 using System;namespace RotatePoint {class Program{static void Main(string[] arg ...

最新文章

  1. 传统图像处理与深度学习又一结合:时空多尺度非局部自相似集成视频超分
  2. C++程序设计(第二版)谭浩强----程序题课后习题答案第二章
  3. 08-01-json-loggin-模块
  4. SQL语句中ON DUPLICATE KEY UPDATE column=IF(条件,值1,值2 ) 的使用
  5. Vue.js组件化开发实践
  6. 深入解析阿里 PouchContainer 如何实现容器原地升级
  7. SpringBoot_日志-slf4j使用原理
  8. WEB请求处理六:浏览器HTTP协议漫谈
  9. python 三维向量 交互_Blender实现Nature of Code1.5单位向量[Nature of Node 004]
  10. python让你再也不为文章配图与素材发愁,让高清图片占满你的硬盘! #华为云·寻找黑马程序员#
  11. 【报告分享】5G网络切片分级白皮书.pdf(附下载链接)
  12. 计算机及网络保密检查记录表,南京航空航天大学涉密计算机保密检查记录表.doc...
  13. 中医meta分析,成功投稿二区期刊
  14. python中xlsxwriter_python模块之XlsxWriter 详解
  15. 施耐德SoMachine Basic中存在高危漏洞(CVE-2018-7783),可读取目标系统上的任意文件...
  16. 努比亚 N1 (Nubia NX541J) 解锁BootLoader 并刷入recovery
  17. 通过数据告诉你centos和debian哪个好?
  18. (18)语义分割--paddle--EISeg自动标注软件的使用和自己数据集的测试
  19. 7 年“键盘手”没在意!某程序员手疼查出骨肿瘤,已让骨头成了“豆腐渣”...
  20. gpgpu学习推荐书籍

热门文章

  1. 48. Be aware of template metaprogramming
  2. hadoop在windows上的环境配置及HDFS API编程示范
  3. docker php 一键部署,Docker Compose 一键部署LNMP
  4. MVCC常问面试题(面试重点)
  5. idea 的精准搜索_intellij idea 的全局搜索快捷键方法
  6. dispimg函数怎么用_excel中的lookup函数究竟该怎么用?如何才能准确理解它的用法?...
  7. 谷粒商城:12.仓储服务 — 仓库管理
  8. 会安装oracle数据库吗,搭建安装oracle数据库
  9. Guava学习笔记(六):Immutable(不可变)集合
  10. Spring Boot 启动参数设置详解