public static Point?GetColorPosition(Color color) { int searchValue = color.ToArgb(); using (Bitmap bmp = GetCaptureUx()) { using (FastBitmap bitmap = new FastBitmap(bmp)) { bitmap.Lock(); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { if (searchValue == bitmap.GetPixelInt(x, y)) { return(new Point((Screen.PrimaryScreen.Bounds.Size.Width / 2) - (1024 / 2) + x, (Screen.PrimaryScreen.Bounds.Size.Height / 2) - (768 / 2) + y)); } } } } } return(null); }
/// <summary> /// Initializes a new instance of the FastBitmapLocker struct with an initial fast bitmap object. /// The fast bitmap object passed will be unlocked after calling Dispose() on this struct /// </summary> /// <param name="fastBitmap">A fast bitmap to attach to this locker which will be released after a call to Dispose</param> public FastBitmapLocker(FastBitmap fastBitmap) { FastBitmap = fastBitmap; }