gpt4 book ai didi

objective-c - 调整 Mac 显示器亮度 Objective-C?

转载 作者:行者123 更新时间:2023-12-03 16:38:19 25 4
gpt4 key购买 nike

有没有办法在 Objective-C 中调整 Mac 的显示亮度?我的眼睛很敏感,有时显示屏看起来可能会更暗。将其与 Jeff's blog post 结合起来关于极客和黑暗,这可能会变得非常烦人。

我认为,如果可以将显示设置为数值,则可以将其设置为低于常规屏幕亮度,这是有道理的。我用 Google 搜索了所有内容,但出现的所有内容都与 iPhone 有关。有没有办法在 Mac 上做到这一点?

最佳答案

刚刚用谷歌搜索了一下,发现了这个:)

这是如何获取亮度的代码。

    // almost completely from: http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
- (float) get_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);

if (err != CGDisplayNoErr)
printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {


CGDirectDisplayID dspy = display[i];
CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
if (originalMode == NULL)
continue;
io_service_t service = CGDisplayIOServicePort(dspy);

float brightness;
err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
&brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"failed to get brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}
return brightness;
}
return -1.0;//couldn't get brightness for any display
}

如何设置亮度。

// almost completely from: http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
- (void) set_brightness:(float) new_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);

if (err != CGDisplayNoErr)
printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {


CGDirectDisplayID dspy = display[i];
CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
if (originalMode == NULL)
continue;
io_service_t service = CGDisplayIOServicePort(dspy);

float brightness;
err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
&brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"failed to get brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}

err = IODisplaySetFloatParameter(service, kNilOptions, kDisplayBrightness,
new_brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"Failed to set brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}

if(brightness > 0.0){
}else{
}
}

}

我在这里找到了它 - http://www.alecjacobson.com/weblog/?tag=brightness .

关于objective-c - 调整 Mac 显示器亮度 Objective-C?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721582/

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