using system;
namespace qq
{
/// <summary>
/// yzm 的摘要說明。
/// </summary>
public class yzm
{
public yzm(public system.drawing.bitmap pic)
{
this.bp = pic;
}
/// <summary>
/// 將一個int值存入到4個字節的字節數組(從高地址開始轉換,最高地址的值以無符號整型參與"與運算")
/// </summary>
/// <param name="thevalue">要處理的int值</param>
/// <param name="thebuff">存放信息的字符數組</param>
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;
}
/// <summary>
/// 將一個ushort值存入到2個字節的字節數組(從高地址開始轉換,最高地址的值以無符號整型參與"與運算")
/// </summary>
/// <param name="thevalue">要處理的ushort值</param>
/// <param name="thebuff">存放信息的字符數組</param>
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);
}
/// <summary>
/// 將4個字節的字節數組轉換成一個int值
/// </summary>
/// <param name="thebuff">字符數組</param>
/// <returns></returns>
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;
}
/// <summary>
/// 將2個字節的字節數組轉換成一個ushort值
/// </summary>
/// <param name="thebuff">字符數組</param>
/// <returns></returns>
public static ushort getushortfrombyte(byte[] thebuff)
{
int jieguo1=0;
jieguo1=(thebuff[0]<<8)+thebuff[1];
ushort jieguo=(ushort)jieguo1;
return jieguo;
}
/// <summary>
/// 將內存中的數據寫入硬盤(保存特征庫)
/// </summary>
/// <param name="thefile">保存的位置</param>
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<datanum;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();
}
/// <summary>
/// 從文件中讀取信息,並保存在內存中相應的位置
/// </summary>
/// <param name="thefile">特征庫文件</param>
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);
fs.read(buff,0,4);
allnum=getintfrombyte(buff);
byte[] buff0=new byte[2];
for(int ii=0;ii<allnum;ii++)
{
for(int jj=0;jj<20;jj++)
{
fs.read(buff0,0,2);
datap[ii,jj]=getushortfrombyte(buff0);
}
fs.read(buff0,0,1);
dataxy[ii,0]=buff0[0];
fs.read(buff0,0,1);
dataxy[ii,1]=buff0[0];
fs.read(buff0,0,1);
datachar[ii]=buff0[0];
}
datanum=allnum;
fs.close();
}
/// <summary>
/// 驗證碼圖片
/// </summary>
public system.drawing.bitmap bp =new system.drawing.bitmap(49,20);
/// <summary>
/// 特征庫的長度
/// </summary>
public static int datanum=0;
/// <summary>
/// 特征庫數據
/// </summary>
public static ushort[,] datap=new ushort[100000,20];
/// <summary>
/// 長度與高度
/// </summary>
public static byte[,] dataxy=new byte[100000,2];