--------------------------------
The main part of the program is bascially this 'for' loop:
int X = 25;
int Y = 25;
Bitmap^ OBJPic = gcnew Bitmap(picCaptcha->Image);
Color Brightest = System::Drawing::Color::White;
Color colCur;
Boolean IsBlack = false;
for (int curX = 0; curX < OBJPic->Width && IsBlack == false; curX += 4
{
for (int curY = 0; curY < OBJPic->Height && IsBlack == false; curY += 4
{
colCur = OBJPic->GetPixel(curX,curY);
if (colCur.GetBrightness() < Brightest.GetBrightness())
{
Brightest = colCur;
X = curX;
Y = curY;
IsBlack = (Brightest == System::Drawing::Color::Black);
}
}
}--------------------------------
Explanation
1. The first part gets the bitmap of the picturebox and assings it to the Bitmap object called "OBJPic".
2. The second part declares a variable called "colBrightest" and assings the color black to it, I know it's not the brightest color. But it's simply called that because a color can't get any darker than black so as soon the the scanner gets a pixel thats black it'll stop because nothing can get darker than black.
3. If you know much about C++ for loops then you can tell I get 2 for loops to scan every pixel of the picture while the the X and Y coords are in range with the picture's height and width and while the current pixel is not black(although it will stop once it finds a black pixel).
4. Now hard coded inside the for loop we assign current pixel's color to a color variable called colColor. If the brightness of the current color is lower than the brightness of black then black becomes the color of the current color and we assign proper values to the X and Y variables.
5. This step is pretty simple but bascially if current color is black then IsBlack becomes true and the for loops will stop.
--------------------------------
Right well thats pretty much what the function does it is slow but you can make more effecient coding by different means which I will post later.
--------------------------------
After you have aquired the right coords you can use this dBox function to draw a small box arround the found pixel.:
void dBox(int X, int Y)
{
if (X != 0 && Y != 0)
{
Bitmap^ OBJBox = gcnew Bitmap(picCaptcha->Image);
OBJBox->SetPixel(X - 2, Y + 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 1, Y + 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X, Y + 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 1, Y + 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 2, Y + 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 2, Y + 1, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 2, Y, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 2, Y - 1, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 2, Y - 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X + 1, Y - 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X, Y - 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 1, Y - 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 2, Y - 2, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 2, Y - 1, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 2, Y, System::Drawing::Color::Black);
OBJBox->SetPixel(X - 2, Y + 1, System::Drawing::Color::Black);
picCaptcha->Image= gcnew Bitmap(OBJBox);
}
else { MessageBox::Show("The fed X or Y coordinate(s) are out of range"); }
}--------------------------------
Note: Both for loops step by 4 so that means that every 4 pixels will be scanned. If there are 24 pixels in one line and the X Step is 4 then out of the 24 pixels only 6 pixels will be scanned. This causes the program to be less accurate but much faster because it scans less pixels. You can always make it more accurate by stepping by 1 instead.
Well thats it I hope you learned a thing or two.
Questions or comments?
This post has been edited by Lord Nikon: 18 March 2006 - 09:20 PM

Help












