Hey, I found a cool class online for finding certain colors in a designated rectangle around your mouse position.
Its optimised for speed, and supposedly works, but when I try compiling it I get around 32 errors.
Heres the code
public static Point PixelSearch(Rectangle rect, int PixelColor, int Shade_Variation)
{
Color Pixel_Color = Color.FromArgb(PixelColor);
Point Pixel_Coords = new Point(-1, -1);
Bitmap RegionIn_Bitmap = CaptureScreenRegion(rect);
BitmapData RegionIn_BitmapData = RegionIn_Bitmap.LockBits(new Rectangle(0, 0, RegionIn_Bitmap.Width, RegionIn_Bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int[] Formatted_Color = new int[3] { Pixel_Color.B, Pixel_Color.G, Pixel_Color.R }; //bgr
unsafe
{
for (int y = 0; y < RegionIn_BitmapData.Height; y++)
{
byte* row = (byte*)RegionIn_BitmapData.Scan0 + (y * RegionIn_BitmapData.Stride);
for (int x = 0; x < RegionIn_BitmapData.Width; x++)
{
if (row[x * 3] >= (Formatted_Color[0] - Shade_Variation) & row[x * 3] <= (Formatted_Color[0] + Shade_Variation)) //blue
{
if (row[(x * 3) + 1] >= (Formatted_Color[1] - Shade_Variation) & row[(x * 3) + 1] <= (Formatted_Color[1] + Shade_Variation)) //green
{
if (row[(x * 3) + 2] >= (Formatted_Color[2] - Shade_Variation) & row[(x * 3) + 2] <= (Formatted_Color[2] + Shade_Variation)) //red
{
Pixel_Coords = new Point(x + rect.X, y + rect.Y);
goto end;
}
}
}
}
}
}
end:
return Pixel_Coords;
}
private static Bitmap CaptureScreenRegion(Rectangle rect)
{
Bitmap BMP = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
GFX.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
return BMP;
}
I found it here > http://www.elitepvpers.de/forum/gamehacking-coding/247732-c-pixelsearch-search-screen-pixel.html
Unsafe code allowing is enabled.
Im using SharpDevelop as my developer.