前置闪光灯亮度 iPhone

Front Flash Brightness iPhone

我已经在一个项目上工作了一段时间了,我想真正解决一件事,但我一直没弄明白。

在应用程序中拍摄前置照片时,我希望使用前置闪光灯让照片更亮。

我使用的是自定义 AVCaptureSession 摄像头,它是全屏的。这是使闪光发生的代码,只是图片一点也不亮。

//Here is the code for a front flash on the picture button press. It does flash, just doesn't help.
UIWindow* wnd = [UIApplication sharedApplication].keyWindow;
UIView *v = [[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)];
[wnd addSubview: v];
v.backgroundColor = [UIColor whiteColor];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration: 1.0];
v.alpha = 0.0f;
[UIView commitAnimations];

//imageView is just the actual view the the cameras image fills.
imageView.hidden = NO;
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections) {
    for(AVCaptureInputPort *port in [connection inputPorts]) {
        if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
            videoConnection = connection;
            break;
        }
    }if (videoConnection) {
        break;
    }

}   [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
    if (imageDataSampleBuffer != NULL) {
        imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
        UIImage *thePicture  = [UIImage imageWithData:imageData];
        self.imageView.image = thePicture;
 //After the picture is on the screen, I just make sure some buttons are supposed to be where they are supposed to be.
        saveButtonOutlet.hidden = NO;
        saveButtonOutlet.enabled = YES;
        diaryEntryOutlet.hidden = YES;
        diaryEntryOutlet.enabled = NO;
    }

}];

}

抓图前需要设置白屏,等待抓图完成后再在completion block中去掉白屏。

您还应该在短暂延迟后发送捕获以确保屏幕变白 -

UIWindow* wnd = [UIApplication sharedApplication].keyWindow;
UIView *v = [[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)];
[wnd addSubview: v];
v.backgroundColor = [UIColor whiteColor];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
        if (imageDataSampleBuffer != NULL) {
            imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *thePicture  = [UIImage imageWithData:imageData];

            dispatch_async(dispatch_get_main_queue(), ^{
                self.imageView.image = thePicture;
                [v removeFromSuperview];
            });
        }
        //After the picture is on the screen, I just make sure some buttons are supposed to be where they are supposed to be.
        saveButtonOutlet.hidden = NO;
        saveButtonOutlet.enabled = YES;
        diaryEntryOutlet.hidden = YES;
        diaryEntryOutlet.enabled = NO;
    }];
}];