永发信息网

C#怎么制作调节屏幕亮度的软件

答案:2  悬赏:80  手机版
解决时间 2021-04-07 15:19
  • 提问者网友:战皆罪
  • 2021-04-06 20:23
C#怎么制作调节屏幕亮度的软件
最佳答案
  • 五星知识达人网友:鱼忧
  • 2021-04-06 21:09
通过平台调用的方式进行开发。
平台调用可以调用windows中的所有dll,但你必须有相关的dll资料,直接调整亮度并不是高级语言开发的目的,本身这种开发将硬件极度抽象,使用开发人员从硬件中脱离出来,所以不存在直接在硬件进行操作方式(除硬件的读写之类的),所以基本这种情况,可以考虑C#中的平台调用方式。
全部回答
  • 1楼网友:三千妖杀
  • 2021-04-06 22:36

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.runtime.interopservices;//必须引用此项

//警告:实验此代码可能给你的显示器的显示带来问题 ,花了两个小时查api的用法 // 不过我试过是没有事情的(bs下自己:不是用自己的机子)

namespace windowsapplication1 ...{     public partial class form1 : form     ...{

    public form1()     ...{     initializecomponent();     }

    private void button1_click(object sender, eventargs e)     ...{     setgamma(trackbar1.value);     }     [dllimport("gdi32.dll")]     public static extern int getdevicegammaramp(intptr hdc, ref ramp lpramp);     ramp ramp = new ramp();

    [dllimport("gdi32.dll")]     public static extern int setdevicegammaramp(intptr hdc, ref ramp lpramp);

    [dllimport("user32.dll")]     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;     }     void setgamma(int gamma)     ...{     ramp.red = new ushort[256];     ramp.green = new ushort[256];     ramp.blue = new ushort[256];

    for (int i = 1; i < 256; i++)     ...{     // gamma 必须在3和44之间     ramp.red[i] = ramp.green[i] = ramp.blue[i] = (ushort)(math.min(65535, math.max(0, math.pow((i + 1) / 256.0, gamma * 0.1) * 65535 + 0.5)));     }     setdevicegammaramp(getdc(intptr.zero), ref ramp);     }

    } }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯