我需要檢測顯示器上像素的顏色。如何在C#中的座標(x,y)上檢索它?如何檢測C#中顯示器上像素的顏色?
回答
您可以使用WINAPI GetPixel(...)
使用Graphics.CopyFromScreen複製一個1x1的位圖,Bitmap.GetPixel()來獲得它的顏色。
謝謝。這似乎是一個簡單的解決方案。 – 2010-11-17 12:05:34
首先,捕捉屏幕。
Rectangle screenRegion = Screen.AllScreens[0].Bounds;
Bitmap screen = new Bitmap(screenRegion.Width, screenRegion.Height, PixelFormat.Format32bppArgb);
Graphics screenGraphics = Graphics.FromImage(screenBitmap);
screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);
Then,get the pixel from the bitmap。
請注意,它只適用於主監視器。如果您需要從其他顯示器捕捉像素,則必須在代碼的第一行更改零索引。 – 2010-11-17 12:03:25
首先導入這些DLL
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
然後寫該方法GetPixelColor(X,Y);
static public System.Drawing.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;
}
調用方法Color clr = GetPixelcolor(50,50);
哇。謝謝。這正是我期待的。 – 2010-11-17 12:28:38
- 1. 如何檢測屏幕上的像素/顏色
- 2. 檢索顏色選擇器上的像素顏色的問題
- 3. 圖像上的檢測顏色
- 4. 系統屏幕上的像素顏色檢測
- 5. 檢測圖像上的大部分黑色像素 - objective-c iOS
- 6. 用C#顯示顏色的顏色?
- 7. 檢測圖像中的顏色斑點
- 8. 圖像中物體的顏色檢測
- 9. C#aforge顏色檢測
- 10. 只顯示固定元素上方的背景圖像/顏色
- 11. 如何更改顯示器的顏色?
- 12. 如何在C#.NET中更改圖像的像素顏色
- 13. 計算羣集中的像素數(Kmeans顏色檢測)
- 14. 如何將顏色C的像素顯示到iPhone座標(x,y)?
- 15. 顏色SURF檢測器
- 16. 如何顯示像素位置和顏色從QGraphicsPixmapItem
- 17. 如何測試我的Java Applet中像素的顏色?
- 18. Java中的顏色檢測器
- 19. 如何檢查Appium中元素的顏色代碼/顏色?
- 20. 如何在iPhone上的圖像上按像素添加顏色?
- 21. 如何在Zsh上顯示Git顏色?
- 22. 如何通過Android上的透明圖像顯示顏色?
- 23. 僅檢測Java中的紅色像素
- 24. C#,EmguCV - 圖像中的顏色和圓圈檢測
- 25. opencv中的顏色檢測
- 26. 如何從PDF中檢測顏色Python
- 27. 如何在圖像視圖中顯示色彩顏色
- 28. 使用Python的圖像顏色檢測
- 29. 使用PHP檢測圖像的顏色
- 30. 檢測圖像的背景顏色
重複,請參閱:http://stackoverflow.com/questions/1483928/how-to-read-the-color-of-a-screen-pixel – Bolu 2010-11-17 11:58:18
您不需要C#。只需使用放大鏡:) – thomaspaulb 2010-11-17 11:58:32