【问题标题】:Use AVFoundation Still Image使用 AVFoundation 静止图像
【发布时间】:2013-11-07 00:46:51
【问题描述】:

我正在使用如下所示的 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];
    }];
}

【问题讨论】:

    标签: ios objective-c avfoundation


    【解决方案1】:

    捕获静止图像只是为了在捕获时输出图像。 使用 AVCaptureVideoPreviewLayer 显示像AVCam code

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多