国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現屏幕亮度和閃光燈控制的實例代碼

2019-10-21 18:46:07
字體:
來源:轉載
供稿:網友

這兩天學習了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];    }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大渡口区| 通河县| 长治县| 舟曲县| 扎鲁特旗| 濉溪县| 惠东县| 永宁县| 贵定县| 婺源县| 黄龙县| 金门县| 贺州市| 广河县| 崇信县| 贞丰县| 利川市| 扶沟县| 灵川县| 刚察县| 萍乡市| 独山县| 上饶县| 吴江市| 莫力| 乳源| 大埔区| 开阳县| 新巴尔虎右旗| 安达市| 上饶县| 鹿泉市| 巴青县| 南汇区| 聊城市| 洛浦县| 荣昌县| 专栏| 七台河市| 乐亭县| 会泽县|