获取屏幕当前颜色过滤器的颜色 [英] Get the colour of the screen's current colour filter

查看:180
本文介绍了获取屏幕当前颜色过滤器的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码将屏幕的颜色过滤器设置为特定颜色。

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")]
private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp);
private static IntPtr hdc;

public unsafe bool SetLCDbrightness(Color c)
{
    short red = c.R;
    short green = c.G;
    short blue = c.B;

    Graphics gg = Graphics.FromHwnd(IntPtr.Zero);
    hdc = gg.GetHdc();

    short* gArray = stackalloc short[3 * 256];
    short* idx = gArray;
    short brightness = 0;
    for (int j = 0; j < 3; j++)
    {
        if (j == 0) brightness = red;
        if (j == 1) brightness = green;
        if (j == 2) brightness = blue;
        for (int i = 0; i < 256; i++)
        {
            int arrayVal = i * (brightness);
            if (arrayVal > 65535) arrayVal = 65535;
            *idx = (short)arrayVal;
            idx++;
        }
    }
    // For some reason, this always returns false?
    bool retVal = SetDeviceGammaRamp(hdc, gArray);
    gg.Dispose();
    return false;
}


推荐答案

=https://stackoverflow.com/questions/11198353/redirect-any-user-input-to-a-separate-underlying-program>其他帖子,以形成以下答案:

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]);
}

这篇关于获取屏幕当前颜色过滤器的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆