我需要检测显示器上像素的颜色。如何在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. 用C#显示颜色的颜色?
- 3. 检测图像中的颜色斑点
- 4. C#aforge颜色检测
- 5. 只显示固定元素上方的背景图像/颜色
- 6. 如何更改显示器的颜色?
- 7. 如何将颜色C的像素显示到iPhone坐标(x,y)?
- 8. 如何显示像素位置和颜色从QGraphicsPixmapItem
- 9. 如何测试我的Java Applet中像素的颜色?
- 10. Java中的颜色检测器
- 11. 如何在iPhone上的图像上按像素添加颜色?
- 12. 如何在图像视图中显示色彩颜色
- 13. AutoCompleteTextView中的颜色如何在AutoCompleteTextView中显示颜色
- 14. 使用PHP检测图像的颜色
- 15. 如何获取图像中像素的颜色(加载灰色)?
- 16. 程序检测单个像素的颜色变化?
- 17. 如何显示灰色图像的颜色图?
- 18. Javascript:检测单色显示
- 19. 检测iDevice颜色
- 20. Java颜色检测
- 21. 如何从Qt中的颜色数据数组显示图像?
- 22. 如何检测位图中的像素是否为黑色
- 23. 如何检测位图中的红色像素
- 24. OpenCV - 具有不同颜色的颜色斑点检测器
- 25. 显示图像的颜色直方图
- 26. 显示图像的背景颜色 - CSS
- 27. C#颜色检测多个结果
- 28. 使用C#进行颜色检测
- 29. OpenCV C++颜色检测和打印Mac
- 30. 如何在C#中的位图图像上应用颜色012
重复,请参阅: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