問題描述
我正在使用 AVFoundation 框架.在我的示例緩沖區委托中,我有以下代碼:
I'm using the AVFoundation framework. In my sample buffer delegate I have the following code:
-(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 仍然是白色的.關于這個問題的任何想法?我正在使用以下內容來設置我的會話:
I am able to use the CIImage to run the face detector etc. but it does not show up in the UIImageView ... the imageView remains white. Any ideas as to the problem? I am using the following to setup my session:
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];
推薦答案
這可能會有所幫助.這段代碼我遇到了同樣的問題(圖像沒有被繪制到屏幕上):
This might help. I was having the same issue (image not being drawn to screen) with this code:
CIImage *image = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"mushroom.jpg"]];
theImageView.image = [UIImage imageWithCIImage:image];
但是,在將代碼更改為此之后,它現在可以正常工作了:
However, after changing the code to this, it now works correctly:
CIImage *image = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"mushroom.jpg"]];
CIContext *context = [CIContext contextWithOptions:nil];
theImageView.image = [UIImage imageWithCGImage:[context createCGImage:image fromRect:image.extent]];
要了解有關 CIContext 的更多信息,請查看此處:http://developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIContext_Class/Reference/Reference.html#//apple_ref/occ/cl/CIContext
To read more about CIContext take a look here: http://developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIContext_Class/Reference/Reference.html#//apple_ref/occ/cl/CIContext
這篇關于在 iOS5 中從 CIImage 創建 UIImage 時遇到問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!