QQ验证码识别源代码(C#/NET1.1)__教程 |
|
日期:2007-5-20 1:27:09 人气:140 [大 中 小] |
|
|
|
using System;
namespace QQ { /// /// yzm 的摘要说明。 /// public class yzm { public yzm(public System.Drawing.Bitmap pic) { this.bp = pic; } /// /// 将一个int值存入到4个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算") /// /// 要处理的int值 /// 存放信息的字符数组 public static void getbytesfromint(int thevalue, byte[] thebuff) { long v1=0; long v2=0; long v3=0; long v4=0; uint b1=(uint)4278190080; uint b2=(uint)16711680; uint b3=(uint)65280; uint b4=(uint)255; v1=thevalue & b1; v2=thevalue & b2; v3=thevalue & b3; v4=thevalue & b4; thebuff[0]=(byte)(v1>>24); thebuff[1]=(byte)(v2>>16); thebuff[2]=(byte)(v3>>8); thebuff[3]=(byte)v4; } /// /// 将一个ushort值存入到2个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算") /// /// 要处理的ushort值 /// 存放信息的字符数组 public static void getbytesfromushort(ushort thevalue, byte[] thebuff) { ushort v1=0; ushort v2=0; ushort b1=(ushort)65280; ushort b2=(ushort)255; v1=(ushort)(thevalue & b1); v2=(ushort)(thevalue & b2); thebuff[0]=(byte)(v1>>8); thebuff[1]=(byte)(v2); } /// /// 将4个字节的字节数组转换成一个int值 /// /// 字符数组 /// public static int getintfrombyte(byte[] thebuff) { int jieguo=0; long mid=0; long m1=0; long m2=0; long m3=0; long m4=0; m1=(thebuff[0]<<24); m2=(thebuff[1]<<16); m3=(thebuff[2]<<8); m4=thebuff[3]; mid=m1+m2+m3+m4; jieguo=(int)mid; return jieguo; } /// /// 将2个字节的字节数组转换成一个ushort值 /// /// 字符数组 /// public static ushort getushortfrombyte(byte[] thebuff) { int jieguo1=0; jieguo1=(thebuff[0]<<8)+thebuff[1]; ushort jieguo=(ushort)jieguo1; return jieguo; } /// /// 将内存中的数据写入硬盘(保存特征库) /// /// 保存的位置 public static void writetofile(string thefile) { System.IO.FileStream fs = new System.IO.FileStream(thefile,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.ReadWrite); byte[] buff0=new byte[4]; getbytesfromint(datanum,buff0); fs.Write(buff0,0,4); for(int ii=0;ii{ for(int jj=0;jj<20;jj++) { byte[] buff=new byte[2]; getbytesfromushort(datap[ii,jj],buff); fs.Write(buff,0,2); } fs.WriteByte(dataxy[ii,0]); fs.WriteByte(dataxy[ii,1]); fs.WriteByte(datachar[ii]); } fs.Close(); } /// /// 从文件中读取信息,并保存在内存中相应的位置 /// /// 特征库文件 public static void readfromfile(string thefile) { int allnum=0; byte[] buff=new byte[4]; System.IO.FileStream fs = new System.IO.FileStream(thefile,System.IO.FileMode.Open,System.IO.FileAccess.Read); |
|
出处:本站原创 作者:佚名 |
|
|