在 iOS5 中从 CIImage 创建 UIImage 时遇到问题

Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中从 CIImage 创建 UIImage 时遇到问题)
本文介绍了在 iOS5 中从 CIImage 创建 UIImage 时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 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 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

问题描述:H5页面,ios点击input框,输入内容时,页面会自动放大,且失焦后需手动放小,要怎么处理呢? 解决办法 meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" width=device
AWS DynamoDB Batch Get Request - iOS(AWS DynamoDB 批量获取请求 - iOS)
Querying DynamoDB on non-key attributes(在非关键属性上查询 DynamoDB)
DynamoDB auto incremented ID amp; server time (iOS SDK)(DynamoDB 自动递增 ID amp;服务器时间(iOS SDK))
Where to find a clear explanation about swift alert (UIAlertController)?(哪里可以找到关于 swift alert (UIAlertController) 的清晰解释?)
Facebook Requests Dialog: Frictionless Requests in native iOS app possible?(Facebook 请求对话框:本机 iOS 应用程序中的无摩擦请求可能吗?)