我正在使用AVFoundation框架。在我的样本缓冲委托我有以下代码:无法在iOS5中从CIImage创建UIImage
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
CVPixelBufferRef pb = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pb];
self.imageView.image = [UIImage imageWithCIImage:ciImage];
}
我能够用CIImage运行脸部检测装置等,但它并没有在UIImageView的出现......在ImageView的保持白色。关于这个问题的任何想法? 我使用下面的设置我的会话:
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPreset640x480;
self.videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
self.frameOutput = [[AVCaptureVideoDataOutput alloc] init];
self.frameOutput.videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
谢谢 - 这确实让我画出图像。但是它会泄漏内存,导致应用程序在运行几秒后崩溃。 – user491880
是的,我还没有真的看太多。我相信你必须在某个时候释放上下文或者CGImageRef。另外我敢肯定上面的方法不是使用CIImage视图的实际方法。 我计划明天观看“在iOS和Mac OS X上使用Core Image”视频(该视频位于Apple开发人员网站上的WWDC 2011会话视频中)并深入了解,如果我学习了一些内容任何有用的。 – spybart
我建议你也看这个视频和/或看演示文稿幻灯片,因为它解释了如何使用核心图像,并详细了解上下文以及何时使用CPU/GPU和更多 – spybart