iOS画面の明るさとフラッシュ制御を実現するコード例


この二日間はiOSの画面の明るさとフラッシュ制御を勉強しましたので、今日は少しノートを追加します。
使用フレーム:AVFoundationフレームとImageIO
画面の明るさを読み取ります。
スクリーンの明るさを設定します。[UScren manScreen]set Brightness: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];  
  }
}

以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。