Get the colour of the screen's current colour filter

流过昼夜 提交于 2019-12-02 02:46:32
Dan W

I adapted this other post to form the following answer:

[DllImport("gdi32.dll")]
public static extern int GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RAMP
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public UInt16[] Red;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public UInt16[] Green;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public UInt16[] Blue;
}

private Color getScreenColor()
{
    RAMP r = new RAMP();
    GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
    return Color.FromArgb(r.Red[1], r.Green[1], r.Blue[1]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!