繁体   English   中英

在iOS 5核心图像过滤器中显示从CIImage获得的UIImage

[英]Displaying UIImage obtained from CIImage in iOS 5 Core Image Filters

我正在使用图像过滤器应用程序。 我使用以下代码创建了过滤器:

context = [CIContext contextWithOptions:nil];



    beginImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"biscus_small.png"]];


    filter = [CIFilter filterWithName:@"CISepiaTone" 
                                  keysAndValues: kCIInputImageKey, beginImage, 
                        @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];

然后,当用户选择过滤器时,我只需在应用过滤器后获取CIImage并将其分配给UIImageView。 出于某种原因,setImage之后的UIImageView显示白色(什么都没有)。

CIImage *outputImage = [filter outputImage];

   // CGImageRef cgimg = 
   // [context createCGImage:outputImage fromRect:[outputImage extent]];

    UIImage *finalImage = [UIImage imageWithCIImage:outputImage];

    [self.imageView setImage:finalImage];

如果我使用CIContext的createCGImage方法,则它可以正常工作并使用过滤器显示图像,但是使用createCGImage的速度非常慢。

CIImage的-createCGImage:fromRect:之所以这么慢的原因是,这实际上触发了光栅位图的处理和输出。 将输出CIImage分配给UIImage不会导致图像被处理并呈现输出。 通过Core Image过滤图像时,您将无法避免此步骤。

正如我在此答案中所述 ,Core Image在iOS 5.1上的性能令人失望。 如果可以提出建议,我已经建立了一个开放源代码框架 ,该框架可以进行GPU加速的图像处理,并且在我测试过的几乎所有情况下都可以胜过Core Image的性能。 对于图像过滤,我的速度比iPhone 4上的Core Image快4倍。

但是,过滤时往返于UIImage仍有一些开销,因此,如果您能够处理原始图像字节,则我的原始数据输入和输出比处理UIImage快得多。 我将在此框架中添加一些直接的JPEG和PNG输入和输出,以为此提供比必须通过UIImage更快的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM