Get the colour of the screen's current colour filter

后端 未结 1 1708
梦毁少年i
梦毁少年i 2021-01-24 11:49

The following code SETS the colour filter of the screen to a specific colour.

How can I instead GET the colour of the screen?

[DllImport(\"GDI32.dll\")]
         


        
相关标签:
1条回答
  • 2021-01-24 12:11

    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]);
    }
    
    0 讨论(0)
提交回复
热议问题