调整屏幕亮度

一种方式是用GSEventSetBacklightLevel的方式设置的,但是会被reject回来的,(在2.0上)
  NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));

  previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.

  [bl release]

  设置屏幕亮度

  GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.

 

在main view 上面再加個view蓋上
把userInteractionEnabled 設成NO, backgroundcolore設成黑色
觸發action時改變這個view 的alpha值
就能做出假的光源控制了

 

实现方法来自于iPhone Dev SDK Forum:

  读取屏幕亮度:

  NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));

  previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.

  [bl release]

  设置屏幕亮度:

  GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.

  后续的问题:

  1.据说读取屏幕亮度的方法只在2.x的firmware有效,因为今天apple mini没在手里,暂时无法验证。

  2.使用上述功能前,需要进入GraphicsServices.h。

  3.因为是私有API,GSEventSetBacklightLevel(float value)这个方法,可能需要自己额外在GraphicsServices.h里定义一下(有待验证),或者使用ToolChain编译。

  4.一般,会涉及到调节屏幕亮度的程序,都会搭配防止休眠的功能,代码很简单:

  [[UIApplication sharedApplication] setIdleTimerDisabled:YES];


 一个偏方
  读取屏幕亮度:

  NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));

  previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.

  [bl release]

  设置屏幕亮度:

  GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.


       注意:GSEventSetBacklightLevel(float value)这个方法,可能需要自己额外在GraphicsServices.h里定义一下
       不然有可能不能通过苹果的审核....因为这个方法像是个擦边球...有点像私有的API

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Gamma Manager is based on Gamma Slider control. This control allows to change gamma monitor on most graphic cards. The goal for this project is very simple and control is for VC6 & VC7. The other day I downloaded a N64 emulator but the screen was so black that I did not see anything. I had thus to find this solution to lighten my screen. I know that the tools of my video chart make it possible to change gamma of my screen, but it is faster with this tool. Implementation The implementation of this slider control is very easy. Import GammaSlider.h and GammaSlider.cpp into your project. Include reference to the class control. Add slider control on a form. Use ClassWizard to declare variable name derived from CGammaSlider control. That's it, enjoy! Under the hood Windows provides two APIs GetDeviceGammaRamp/ SetDeviceGammaRamp to perform gamma correction. In fact we need to have a 3 dimensional buffer of 256 WORD to manipulate gamma correction. To change gamma, it is necessary to change the RGB value of each color contained in the buffer by a float factor between 0.0 and 2.0. Example We need to save current gamma for future restore. Collapse Copy CodeWORD m_RampSaved[256*3]; if (!GetDeviceGammaRamp(::GetDC(NULL), m_RampSaved)) { TRACE("WARNING: Cannot initialize DeviceGammaRamp.\n"); }To change gamma, cycle into ramp buffer and change RGB color where Gamma is the float factor. Collapse Copy CodeWORD ramp[256*3]; for( int i=0; i<256; i++ ) { ramp[i+0] = ramp[i+256] = ramp[i+512] = (WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5)); } SetDeviceGammaRamp(::GetDC(NULL), ramp);Now to trap slider control message, we need to use a special message ON_WM_HSCROLL_REFLECT() that can provide message to be dispatched into control class itself.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值