iOS中屏幕亮度與閃光燈控制詳解
本文主要介紹的是關(guān)于iOS屏幕亮度與閃光燈控制的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面來(lái)看看詳細(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的值來(lái)打開(kāi)和關(guān)閉閃光燈
AVCaptureDevice*device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
BOOL result = [device hasTorch];// 判斷設(shè)備是否有閃光燈
if((brightnessValue <0) && result) {
// 打開(kāi)閃光燈
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];//開(kāi)
[device unlockForConfiguration];
}else if((brightnessValue >0) && result) {
// 關(guān)閉閃光燈
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];//關(guān)
[device unlockForConfiguration];
}
}
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)
這篇文章主要介紹了IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)的相關(guān)資料,需要的朋友可以參考下2017-05-05
iOS中setValue和setObject的區(qū)別詳解
setObject:ForKey: 是NSMutableDictionary特有的;setValue:ForKey:是KVC的主要方法。接下來(lái)通過(guò)本文給大家分享iOS中setValue和setObject的區(qū)別,需要的朋友參考下2017-02-02
CocoaPods 出現(xiàn)LoadError - cannot load such file -- nanaimo錯(cuò)誤解決
這篇文章主要介紹了CocoaPods 出現(xiàn)LoadError - cannot load such file -- nanaimo錯(cuò)誤解決辦法的相關(guān)資料,需要的朋友可以參考下2017-04-04
iOS實(shí)現(xiàn)搭建聊天頁(yè)面的實(shí)例代碼
本篇文章主要介紹了iOS實(shí)現(xiàn)搭建聊天頁(yè)面的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07
iOS實(shí)現(xiàn)遠(yuǎn)程推送原理及過(guò)程
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)遠(yuǎn)程推送原理及具體過(guò)程,圖文結(jié)合的方式針對(duì)iOS遠(yuǎn)程推送進(jìn)行分析,感興趣的小伙伴們可以參考一下2016-05-05

