欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS中屏幕亮度與閃光燈控制詳解

 更新時間:2017年06月01日 09:58:51   作者:呀咪9527  
這篇文章主要給大家介紹了關(guān)于iOS中屏幕亮度與閃光燈控制的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。

本文主要介紹的是關(guān)于iOS屏幕亮度與閃光燈控制的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面來看看詳細(xì)的介紹:

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

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

設(shè)置屏幕亮度: [[UIScreen mainScreen] setBrightness:0.5];

獲取環(huán)境亮度主要代碼:

- (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);
 // 根據(jù)brightnessValue的值來打開和關(guān)閉閃光燈
 AVCaptureDevice*device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
 BOOL result = [device hasTorch];// 判斷設(shè)備是否有閃光燈
 if((brightnessValue <0) && result) {
 // 打開閃光燈
  [device lockForConfiguration:nil];
  [device setTorchMode:AVCaptureTorchModeOn];//開
  [device unlockForConfiguration];
 }else if((brightnessValue >0) && result) {
 // 關(guān)閉閃光燈
  [device lockForConfiguration:nil];  
  [device setTorchMode:AVCaptureTorchModeOff];//關(guān)
  [device unlockForConfiguration]; 
 }
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論