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]; 
 }
}
締め括りをつける
以上はこの文章の全部の内容です。本文の内容は皆さんの学習や仕事に一定の助けをもたらすことを望んでいます。もし疑問があれば、メッセージを残して交流してください。ありがとうございます。