gpt4 book ai didi

c# - 获取屏幕当前滤色器的颜色

转载 作者:太空宇宙 更新时间:2023-11-04 03:40:32 24 4
gpt4 key购买 nike

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

我怎样才能获取屏幕的颜色?

[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;
}

最佳答案

我改编了这个other post形成以下答案:

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

关于c# - 获取屏幕当前滤色器的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29076359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com