using
System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Net;
using System.Net.Sockets;
namespace LeadBBSEnder
{
/// <summary>
/// ValidateCode 的摘要说明。
/// </summary>
public sealed class RunningRes
{
private static TcpClienter _tc;
public static TcpClienter Tcp
{
get
{
if( _tc == null )
_tc = new TcpClienter( string.Empty , new IPEndPoint(IPAddress.Any , 1710) , new IPEndPoint(IPAddress.Parse( "221.12.79.162" ) , 80) );
return _tc;
}
}
public static string GetValidateCode( Bitmap bm )
{
short s1 = Paste( bm , Position.Char1 );
short s2 = Paste( bm , Position.Char2 );
short s3 = Paste( bm , Position.Char3 );
short s4 = Paste( bm , Position.Char4 );
return string.Format("{0}{1}{2}{3}" , s1 , s2 , s3 , s4 );
}
private static Point GetOffsetPoint( Position p )
{
switch( p )
{
case Position.Char1:
return new Point( 2 , 1 );
case Position.Char2:
return new Point( 9 , 1 );
case Position.Char3:
return new Point( 16 , 1 );
default:
return new Point( 23 , 1 );
}
}
private static short Paste( Bitmap bm , Position pc )
{
short[,] Char0 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 0,1,1,1,1,0 }
};
short[,] Char1 = {
{ 0,0,1,1,0,0 },
{ 0,1,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,1,1,1,1,0 }
};
short[,] Char2 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 0,0,0,1,1,0 },
{ 0,0,1,1,0,0 },
{ 0,1,1,0,0,0 },
{ 1,1,0,0,0,0 },
{ 1,1,1,1,1,1 }
};
short[,] Char3 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 0,0,0,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0) )
return 0;
if( Paste(bm,Sp,Char1) )
return 1;
if( Paste(bm,Sp,Char2) )
return 2;
if( Paste(bm,Sp,Char3) )
return 3;
if( Paste(bm,Sp,Char4) )
return 4;
if( Paste(bm,Sp,Char5) )
return 5;
if( Paste(bm,Sp,Char6) )
return 6;
if( Paste(bm,Sp,Char7) )
return 7;
if( Paste(bm,Sp,Char8) )
return 8;
if( Paste(bm,Sp,Char9) )
return 9;
throw new Exception("解释不到!");
}
private static bool Paste( Bitmap bm , Point offset, short[,] Char )
{
for( int i = 0 ; i < 8 ; i++ )
{
for( int j = 0 ; j < 6 ; j++ )
{
Color Pc = bm.GetPixel( offset.X + j , offset.Y + i );
if( Pc.A == 255 && Char[i,j] == 1 || Pc.A == 0 && Char[i,j] == 0 )
continue;
else
return false;
}
}
return true;
}
}
internal enum Position
{
Char1,Char2,Char3,Char4
}
}
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Net;
using System.Net.Sockets;
namespace LeadBBSEnder
{
/// <summary>
/// ValidateCode 的摘要说明。
/// </summary>
public sealed class RunningRes
{
private static TcpClienter _tc;
public static TcpClienter Tcp
{
get
{
if( _tc == null )
_tc = new TcpClienter( string.Empty , new IPEndPoint(IPAddress.Any , 1710) , new IPEndPoint(IPAddress.Parse( "221.12.79.162" ) , 80) );
return _tc;
}
}
public static string GetValidateCode( Bitmap bm )
{
short s1 = Paste( bm , Position.Char1 );
short s2 = Paste( bm , Position.Char2 );
short s3 = Paste( bm , Position.Char3 );
short s4 = Paste( bm , Position.Char4 );
return string.Format("{0}{1}{2}{3}" , s1 , s2 , s3 , s4 );
}
private static Point GetOffsetPoint( Position p )
{
switch( p )
{
case Position.Char1:
return new Point( 2 , 1 );
case Position.Char2:
return new Point( 9 , 1 );
case Position.Char3:
return new Point( 16 , 1 );
default:
return new Point( 23 , 1 );
}
}
private static short Paste( Bitmap bm , Position pc )
{
short[,] Char0 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1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,1,0 },
{ 0,0,0,1,1,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 },
{ 0,0,1,1,0,0 }
};
short[,] Char8 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 0,1,1,1,1,0 }
};
short[,] Char9 = {
{ 0,1,1,1,1,0 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 1,1,0,0,1,1 },
{ 0,1,1,1,1,1 },
{ 0,0,0,0,1,1 },
{ 0,1,1,0,1,1 },
{ 0,1,1,1,1,0 }
};
Point Sp = GetOffsetPoint( pc );
if( Paste(bm,Sp,Char0) )
return 0;
if( Paste(bm,Sp,Char1) )
return 1;
if( Paste(bm,Sp,Char2) )
return 2;
if( Paste(bm,Sp,Char3) )
return 3;
if( Paste(bm,Sp,Char4) )
return 4;
if( Paste(bm,Sp,Char5) )
return 5;
if( Paste(bm,Sp,Char6) )
return 6;
if( Paste(bm,Sp,Char7) )
return 7;
if( Paste(bm,Sp,Char8) )
return 8;
if( Paste(bm,Sp,Char9) )
return 9;
throw new Exception("解释不到!");
}
private static bool Paste( Bitmap bm , Point offset, short[,] Char )
{
for( int i = 0 ; i < 8 ; i++ )
{
for( int j = 0 ; j < 6 ; j++ )
{
Color Pc = bm.GetPixel( offset.X + j , offset.Y + i );
if( Pc.A == 255 && Char[i,j] == 1 || Pc.A == 0 && Char[i,j] == 0 )
continue;
else
return false;
}
}
return true;
}
}
internal enum Position
{
Char1,Char2,Char3,Char4
}
}