use*_*880 17 iphone core-image avfoundation ios ios5
我正在使用AVFoundation框架.在我的示例缓冲区委托中,我有以下代码:
-(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];
}
Run Code Online (Sandbox Code Playgroud)
我可以使用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];
Run Code Online (Sandbox Code Playgroud)
spy*_*art 35
这可能有所帮助.使用此代码我遇到了同样的问题(图像没有被绘制到屏幕上):
CIImage *image = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"mushroom.jpg"]];
theImageView.image = [UIImage imageWithCIImage:image];
Run Code Online (Sandbox Code Playgroud)
但是,在将代码更改为此后,它现在可以正常工作:
CIImage *image = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"mushroom.jpg"]];
CIContext *context = [CIContext contextWithOptions:nil];
theImageView.image = [UIImage imageWithCGImage:[context createCGImage:image fromRect:image.extent]];
Run Code Online (Sandbox Code Playgroud)
要了解有关CIContext的更多信息,请访问:http: //developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIContext_Class/Reference/Reference.html#//apple_ref/occ/cl/CIContext
这是我让它工作的一种方式:
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef ref = [context createCGImage:result fromRect:ciImage.extent];
self.imgView.image = [UIImage imageWithCGImage:ref scale:1.0 orientation:UIImageOrientationRight];
CGImageRelease(ref);
Run Code Online (Sandbox Code Playgroud)
注意:多次创建上下文非常糟糕,实际上会导致内存泄漏.您应该只在类实例中创建一次属性作为属性并重用它!
归档时间: |
|
查看次数: |
15501 次 |
最近记录: |