我已经在一个项目上工作了一段时间,我遇到了一件我想真正解决的事情,我一直无法弄清楚。

在应用程序中,当拍摄正面照片时,我希望正面闪光灯实际上使照片更亮。

我正在使用自定义的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;
    }

}];

}

最佳答案

您需要在捕获图像之前将屏幕设置为白色,等待捕获完成,然后在完成区域中删除白色屏幕。

您还应在短暂的延迟后调度捕获,以确保屏幕变白-

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;
    }];
}];

关于ios - 前闪光灯亮度iPhone,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28911227/

10-09 02:15