C#中怎么调整屏幕亮度,饱和度!!!!
答案:3 悬赏:60 手机版
解决时间 2021-02-23 05:55
- 提问者网友:风月客
- 2021-02-22 06:40
请大虾提出宝贵意见。。。。
最佳答案
- 五星知识达人网友:大漠
- 2021-02-22 07:18
找找windows.environment要不就是system.environment,里边没准有,想不起来了。。。
全部回答
- 1楼网友:一把行者刀
- 2021-02-22 08:34
需要相应的API函数的支持
- 2楼网友:舊物识亽
- 2021-02-22 08:06
微软提供屏幕亮度调节api的,网上教程也很多,这里有个很好的图文教程:c#亮度调节教程
大致就是调用
setdevicegammaramp()这个函数来调整屏幕gamma值。在visual studio中新建个窗体应用,然后搞一个滑条以及按钮,代码如下:
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
using system.runtime.interopservices;
namespace brightnesscontrol
{
public partial class form1 : form
{
[dllimport("gdi32.dll")]
private unsafe static extern bool setdevicegammaramp(int32 hdc, void* ramp);
private static bool initialized = false;
private static int32 hdc;
private static int a;
public form1()
{
initializecomponent();
}
private static void initializeclass()
{
if (initialized)
return;
hdc = graphics.fromhwnd(intptr.zero).gethdc().toint32();
initialized = true;
}
public static unsafe bool setbrightness(int brightness)
{
initializeclass();
if (brightness > 255)
brightness = 255;
if (brightness < 0)
brightness = 0;
short* garray = stackalloc short[3 * 256];
short* idx = garray;
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 256; i++)
{
int arrayval = i * (brightness + 128);
if (arrayval > 65535)
arrayval = 65535;
*idx = (short)arrayval;
idx++;
}
}
bool retval = setdevicegammaramp(hdc, garray);
return retval;
}
private void trackbar1_scroll(object sender, eventargs e)
{
}
private void button1_click(object sender, eventargs e)
{
a = trackbar1.value;
setbrightness(a);
}
}
}拖动滑条 点击按钮就可以了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯