135-1821-9792

iOS中屏幕亮度与闪光灯控制的示例分析-创新互联

这篇文章主要介绍iOS中屏幕亮度与闪光灯控制的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:空间域名、雅安服务器托管、营销软件、网站建设、合阳网站维护、网站推广。

所用涉及框架:AVFoundation框架和ImageIO

读取屏幕亮度:[UIScreen mainScreen].brightness;

设置屏幕亮度:[[UIScreen mainScreen] setBrightness:0.5];

获取环境亮度主要代码:

- (void)getTorch {
 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
 AVCaptureDeviceInput *input = [[AVCaptureDeviceInput alloc]initWithDevice:device error:nil];
 AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
 [output setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
 self.session = [[AVCaptureSession alloc]init];
 [self.session setSessionPreset:AVCaptureSessionPresetHigh];
 if ([self.session canAddInput:input]) {
  [self.session addInput:input];
 }
 if ([self.session canAddOutput:output]) {
  [self.session addOutput:output];
 }
 [self.session startRunning];

}

- (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection {
 CFDictionaryRef metadataDict =CMCopyDictionaryOfAttachments(NULL,sampleBuffer, 
 kCMAttachmentMode_ShouldPropagate);
 NSDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:
 (__bridgeNSDictionary*)metadataDict];

 CFRelease(metadataDict);
 NSDictionary *exifMetadata = [[metadata objectForKey:(NSString*)kCGImagePropertyExifDictionary] mutableCopy];
 float brightnessValue = [[exifMetadata objectForKey:(NSString*)kCGImagePropertyExifBrightnessValue] floatValue];
 NSLog(@"%f",brightnessValue);
 // 根据brightnessValue的值来打开和关闭闪光灯
 AVCaptureDevice*device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
 BOOL result = [device hasTorch];// 判断设备是否有闪光灯
 if((brightnessValue <0) && result) {
 // 打开闪光灯
  [device lockForConfiguration:nil];
  [device setTorchMode:AVCaptureTorchModeOn];//开
  [device unlockForConfiguration];
 }else if((brightnessValue >0) && result) {
 // 关闭闪光灯
  [device lockForConfiguration:nil];  
  [device setTorchMode:AVCaptureTorchModeOff];//关
  [device unlockForConfiguration]; 
 }
}

以上是“iOS中屏幕亮度与闪光灯控制的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联网站建设公司行业资讯频道!

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:iOS中屏幕亮度与闪光灯控制的示例分析-创新互联
文章来源:http://kswsj.com/article/ddeoci.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号