从Windows服务获取像素颜色(屏幕)。 C#

时间:2017-07-04 23:00:50

标签: c# service colors pixel

我正在使用此方法获取屏幕上特定像素的颜色

public static Color GetColorAt(int x, int y)    
{
   IntPtr desk = Win32.GetDesktopWindow();
   IntPtr dc = Win32.GetWindowDC(desk);
   int a = (int)Win32.GetPixel(dc, x, y);
   Win32.ReleaseDC(desk, dc);
   return Color.FromArgb(255, (a >> 0) & 0xff, (a >> 8) & 0xff, (a >> 16) & 0xff);
 }

然而,它在控制台或Windows应用程序中正常工作 从Windows服务运行时,它返回无效的颜色。

(Win32类从c#调用dllImport代码)

0 个答案:

没有答案