2
我正在運行全屏遊戲,我試圖找出中間像素的顏色。然而,我使用的代碼似乎只適用於窗口化的應用程序/遊戲/等。這是我的代碼:獲取C#(全屏遊戲)中的中間屏幕像素(顏色)?
public static Color GetPixelColor(int x, int y)
{
IntPtr hdc = GetDC(IntPtr.Zero);
uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
(int)(pixel & 0x0000FF00) >> 8,
(int)(pixel & 0x00FF0000) >> 16);
return color;
}
,我發現了中間的屏幕像素是這樣的:
int ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
int ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
那麼,怎樣才能讓我這個代碼與全屏幕遊戲兼容? 它給了我一個ARGB值A = 255, R = 0, G = 0, B = 0
,儘管我100%肯定中間屏幕像素是紅色的。
首先,你必須按相反的順序(BGR)的RGB參數。 –
請不要發佈重複的問題:http://stackoverflow.com/questions/11173287/getting-a-pixel-from-the-screen-in-a-full-screen-game-c-windows –
我的道歉,但我非常渴望儘快解決這個問題。我將刪除另一個。 – ZimZim