public int Compare( Bitmap bmp, RECT rect, Bitmap bmpFont, RECT rectFont, byte color ) { int result = 0; for (int x = 0; x < rect.Width; ++x ) { for ( int y = 0; y < rect.Height; ++y ) { Color cBmp = bmp.GetPixel( rect.Left + x, rect.Top + y); Color cFont = Color.Black; if ( x < rectFont.Width && y < rectFont.Height ) { cFont = bmpFont.GetPixel( rectFont.Left + x, rectFont.Top + y); } if ( cBmp.R > color && cFont.R > color || cBmp.R < color && cFont.R < color ) { ++result; } } } return result * 100 / ( rect.Width * rect.Height ); }
public char GetCharacter( Bitmap bmp, RECT rect ) { char result = '\0'; int maxCertainty = 0; for (int i = 0; i < rects.Count; ++i ) { int certainty = Compare( bmp, rect, font, rects[ i ], 0xd0); if ( certainty > 90 && certainty > maxCertainty ) { maxCertainty = certainty; result = characters[i]; } } return result; }
public static IList<RECT> Chop( Bitmap bmp, RECT crop, byte color ) { List<RECT> list = new List<RECT>(); RECT rect = new RECT(crop.Left, crop.Top, crop.Right, crop.Bottom); Boolean found = false; Boolean oldFound = false; for (int x = crop.Left; x < crop.Right; ++x ) { found = false; for ( int y = crop.Top; y < crop.Bottom; ++y ) { found = found || bmp.GetPixel(x, y).R >= color; } if ( found && !oldFound ) { rect.Left = x; } else if ( !found && oldFound ) { rect.Right = x; list.Add( Crop( bmp, rect, color ) ); } oldFound = found; } if ( found ) { rect.Right = crop.Right; list.Add(Crop(bmp, rect, color)); } return list; }
public static RECT Crop( Bitmap bmp, RECT rect, byte color ) { RECT reverse = new RECT(rect.Right, rect.Bottom, rect.Left, rect.Top); for( int x = rect.Left; x < rect.Right; ++x ) { for ( int y = rect.Top; y < rect.Bottom; ++y ) { Color pixel = bmp.GetPixel(x, y); if ( pixel.R >= color ) { if ( x < reverse.Left ) { reverse.Left = x; } if ( x >= reverse.Right ) { reverse.Right = x + 1; } if ( y < reverse.Top ) { reverse.Top = y; } if ( y >= reverse.Bottom ) { reverse.Bottom = y + 1; } } } } return reverse; }
public bool Equals(RECT r) { return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom; }