验证码识别封装类

上传人:子 文档编号:43836288 上传时间:2018-06-07 格式:DOCX 页数:6 大小:41.23KB
返回 下载 相关 举报
验证码识别封装类_第1页
第1页 / 共6页
验证码识别封装类_第2页
第2页 / 共6页
验证码识别封装类_第3页
第3页 / 共6页
验证码识别封装类_第4页
第4页 / 共6页
验证码识别封装类_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《验证码识别封装类》由会员分享,可在线阅读,更多相关《验证码识别封装类(6页珍藏版)》请在金锄头文库上搜索。

1、using System;using System.Collections.Generic;using System.Text;using System.Collections;using System.Drawing;using System.Drawing.Imaging;using System.Runtime.InteropServices;namespace BallotAiying2class UnCodebasepublic Bitmap bmpobj;public UnCodebase(Bitmap pic)bmpobj = new Bitmap(pic); /转换为 Form

2、at32bppRgb/ / 根据 RGB,计算灰度值/ / Color 值/ 灰度值,整型private int GetGrayNumColor(System.Drawing.Color posClr)return (posClr.R * 19595 + posClr.G * 38469 + posClr.B * 7472) 16;/ / 灰度转换,逐点方式/ public void GrayByPixels()for (int i = 0; i / 去图形边框/ / public void ClearPicBorder(int borderWidth)for (int i = 0; i bm

3、pobj.Width - 1 -borderWidth | i bmpobj.Height - 1 - borderWidth)bmpobj.SetPixel(j, i, Color.FromArgb(255, 255, 255);/ / 灰度转换,逐行方式/ public void GrayByLine()Rectangle rec = new Rectangle(0, 0, bmpobj.Width, bmpobj.Height);BitmapData bmpData = bmpobj.LockBits(rec, ImageLockMode.ReadWrite, bmpobj. Pixel

4、Format);/ PixelFormat.Format32bppPArgb);/ bmpData.PixelFormat = PixelFormat.Format24bppRgb;IntPtr scan0 = bmpData.Scan0;int len = bmpobj.Width * bmpobj.Height;int pixels = new intlen;Marshal.Copy(scan0, pixels, 0, len);/对图片进行处理int GrayValue = 0;for (int i = 0; i / 得到有效图形并调整为可平均分割的大小/ / 灰度背景分界值/ 有效字符

5、数/ public void GetPicValidByValue(int dgGrayValue, int CharsCount)int posx1 = bmpobj.Width; int posy1 = bmpobj.Height;int posx2 = 0; int posy2 = 0;for (int i = 0; i j) posx1 = j;if (posy1 i) posy1 = i;if (posx2 leftSpan)posx1 = posx1 - leftSpan;if (posx2 + Span - leftSpan / 得到有效图形,图形为类变量/ / 灰度背景分界值/

6、 有效字符数/ public void GetPicValidByValue(int dgGrayValue)int posx1 = bmpobj.Width; int posy1 = bmpobj.Height;int posx2 = 0; int posy2 = 0;for (int i = 0; i j) posx1 = j;if (posy1 i) posy1 = i;if (posx2 / 得到有效图形,图形由外面传入/ / 灰度背景分界值/ 有效字符数/ public Bitmap GetPicValidByValue(Bitmap singlepic, int dgGrayVal

7、ue)int posx1 = singlepic.Width; int posy1 = singlepic.Height;int posx2 = 0; int posy2 = 0;for (int i = 0; i j) posx1 = j;if (posy1 i) posy1 = i;if (posx2 / 平均分割图片/ / 水平上分割数/ 垂直上分割数/ 分割好的图片数组public Bitmap GetSplitPics(int RowNum,int ColNum)if (RowNum = 0 | ColNum = 0)return null;int singW = bmpobj.Wi

8、dth / RowNum;int singH = bmpobj.Height / ColNum;Bitmap PicArray=new BitmapRowNum*ColNum;Rectangle cloneRect;for (int i = 0; i / 返回灰度图片的点阵描述字串,1 表示灰点,0 表示背景/ / 灰度图/ 背前景灰色界限/ public string GetSingleBmpCode(Bitmap singlepic, int dgGrayValue)Color piexl;string code = “;for (int posy = 0; posy singlepic.Height; posy+)for (int posx = 0; posx singlepic.Width; posx+)piexl = singlepic.GetPixel(posx, posy);if (piexl.R dgGrayValue) / Color.Black )code = code + “1“;elsecode = code + “0“;return code;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号