【发布时间】:2014-02-25 15:48:38
【问题描述】:
我想使用 AVCaptureSession 在我的 iOS 应用程序中捕获图像。 根据 Apple 的 AVCam https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html 示例中的代码,我尝试在每次捕获图像时显示预览 ImageView。
// Capture a still image.
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
}
}];
捕获后调用processImage
- (void) processImage:(UIImage *)image
{
[[self postButton] setEnabled:YES];
[[self postButton] setHidden:NO];
[[self cancelButton] setEnabled:YES];
[[self cancelButton] setHidden:NO];
_preview = [[UIImageView alloc] init];
[_preview setImage:image];
_preview.hidden = NO;
}
但 ImageView 在显示时仍然保持不变/为空。
有人可以帮我吗?
【问题讨论】:
标签: ios avcapturesession