gpt4 book ai didi

ios - 前置闪光灯亮度 iPhone

转载 作者:行者123 更新时间:2023-11-29 02:14:26 25 4
gpt4 key购买 nike

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

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com