我正在使用如下所示的 AVFoundation 拍摄静止图像,并且我正在尝试使用 captureImage (UIImage) 显示在不同的视图控制器上,无论我尝试什么,图像 captureImage 都不会显示在任何地方。我的问题是,按原样使用该 captureImage 是否是可以在任何地方使用和显示的完整图像?我已经看到了很多关于 AVFoundation 相机缓冲区的信息,但我不确定是否需要将要使用的图像从缓冲区转换为实际的 UIImage。
- (void) captureStillImage
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
videoConnection = connection;
break;
}
}
if (videoConnection) {
break;
}
}
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
captureImage = [[UIImage alloc] initWithData:imageData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"photoTaken" object:nil userInfo:nil];
}];
}