gpt4 book ai didi

iphone - 为什么从不调用 AVCaptureStillImageOutput::captureStillImageAsynchronouslyFromConnection:completionHandler?

转载 作者:可可西里 更新时间:2023-11-01 03:29:10 24 4
gpt4 key购买 nike

我尝试构建一个从 iPhone 相机捕获帧并对这些帧进行一些处理的应用程序。我尝试了一些在互联网上找到的代码,例如这里:How to capture image without displaying preview in iOS

最后我得到了以下代码:

-(IBAction)captureNow{
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; }
}

// NSLog(@"about to request a capture from: %@", stillImageOutput);
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments)
{
// Do something with the attachments.
NSLog(@"attachements: %@", exifAttachments);
}
else
NSLog(@"no attachments");

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];

// do the processing with the image
}

但是,应用程序永远不会进入 captureStillImageAsynchronouslyFromConnection 方法的处理程序代码块,因此我永远不会从框架中获取图像。我做错事了吗?感谢您的建议!

最佳答案

我发现指向 AVCaptureSession 的指针在自动引用计数模式下没有被 AVCaptureStillImageOutput 正确保留。

这意味着您有两个选择:

关于iphone - 为什么从不调用 AVCaptureStillImageOutput::captureStillImageAsynchronouslyFromConnection:completionHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14690484/

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