public static Bitmap extractImage(Bitmap bmp)
{
try {
for (int w = 0; w < bmp.Width; w++) {
for (int h = 0; h < bmp.Height; h++){
Color c = bmp.GetPixel(w, h);
if (c.R == 226 && c.G == 226 && c.B == 226){
Color c2 = Color.Red;
bmp.SetPixel(w, h, c2);
}
}
}
//ScreenCapture.saveBitmap("red_zones.png", bmp);
int topRedY = detectFirstRedLine(bmp);
topRedY = detectEndFirtRedLine(bmp, topRedY);
if (topRedY != -1) {
bmp = cutTopImage(bmp, 0, topRedY);
//ScreenCapture.saveBitmap("top_red_zones.png", bmp);
int bottomRedY = detectFirstRedLine(bmp);
if (bottomRedY != -1){
int startY = (bottomRedY > 0) ? (bottomRedY * -1) : 0;
bmp = cutImage(bmp, bmp.Width, bottomRedY, 0, 0);
//ScreenCapture.saveBitmap("bottom_red_zones.png", bmp);
int leftRedX = detectSecondRedLine(bmp);
leftRedX = detectEndSecondRedLine(bmp, leftRedX);
bmp = cutTopImage(bmp, leftRedX, 0);
//ScreenCapture.saveBitmap("left_red_zones.png", bmp);
leftRedX = detectSecondRedLine(bmp);
bmp = cutImage(bmp, leftRedX, bmp.Height, 0, 0);
//ScreenCapture.saveBitmap("rigth_red_zones.png", bmp);
}
}
for (int w = 0; w < bmp.Width; w++)
{
for (int h = 0; h < bmp.Height; h++)
{
Color c = bmp.GetPixel(w, h);
if (c.R == 255)
{
Color c2 = Color.FromArgb(0, 226, 226, 226);
bmp.SetPixel(w, h, c2);
}
}
}
}catch(Exception e){}
return bmp;
}