Jak*_*kub 7 iphone capture avfoundation ios
我尝试构建一个从iPhone相机捕获帧的应用程序,并使用这些帧进行一些处理.我尝试了在互联网上找到的一些代码,例如:如何捕获图像而不在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
}
Run Code Online (Sandbox Code Playgroud)
但是,应用程序永远不会进入captureStillImageAsynchronouslyFromConnection方法的处理程序代码块,因此我永远不会从框架中获取图像.我是以错误的方式做某事吗?谢谢你的建议!
归档时间: |
|
查看次数: |
3431 次 |
最近记录: |