[DllImport(“gdi32.dll”)]
static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
[DllImport(“gdi32.dll”)]
static public extern IntPtr CreateDC(string driverName, string deviceName, string output, IntPtr lpinitData);
[DllImport(“gdi32.dll”)]
static public extern bool DeleteDC(IntPtr DC);
static public byte GetRValue(uint color)
{
return (byte)color;
}
static public byte GetGValue(uint color)
{## 读鼠标位置的颜色
return ((byte)(((short)(color)) >> 8));
}
static public byte GetBValue(uint color)
{
return ((byte)((color) >> 16));
}
static public byte GetAValue(uint color)
{
return ((byte)((color) >> 24));
}
public Color GetColor(Point screenPoint)
{
IntPtr displayDC = CreateDC(“DISPLAY”, null, null, IntPtr.Zero);
uint colorref = GetPixel(displayDC, screenPoint.X, screenPoint.Y);
DeleteDC(displayDC);
byte Red = GetRValue(colorref);
byte Green = GetGValue(colorref);
byte Blue = GetBValue(colorref);
return Color.FromArgb(Red, Green, Blue);
}
获取鼠标所在位置颜色
最新推荐文章于 2025-04-25 14:27:21 发布