1

我在我的应用程序中使用了一堆CIFilter滤镜来调整亮度、饱和度等,它们工作正常。我遇到了一些问题inputSharpness。如果我触摸锐度滑块,图片就会消失。相关代码:

UIImage *aUIImage = [imageView image];
CGImageRef aCGImage = aUIImage.CGImage;
aCIImage = [CIImage imageWithCGImage:aCGImage];

//Create context
context = [CIContext contextWithOptions:nil];
sharpFilter = [CIFilter filterWithName:@"CIAttributeTypeScalar" keysAndValues: @"inputImage", aCIImage, nil];

……

- (IBAction)sharpSliderChanged:(id)sender
{

    //Set filter value
    [sharpFilter setValue:[NSNumber numberWithFloat:sharpSlider.value] forKey:@"inputSharpness"];

    //Convert CIImage to UIImage
    outputImage = [sharpFilter outputImage];
    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
    newUIImage = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);

    //add image to imageView
    [imageView setImage:newUIImage];

}
4

1 回答 1

1

我读过一篇有类似问题的帖子,可能的解决方案是为您要提供的 UIImage 效果添加一个类别。这里唯一的区别是您应该使用CIColorControls参数之一:inputSharpnessCISharpenLuminance过滤器。

回到您的问题:从您的评论看来,您对如何初始化过滤器有一些问题。我看了一下官方文档,我会CISharpenLuminance在初始化阶段使用。它仅在 ios 6 中可用。

编辑 就像我说的,如果你想坚持核心图像,你想要的功能只在 iOS 6 上可用。如果您想与 ios 5 兼容,我可以建议您使用第三方库: bradlarson 的GPU 库。

于 2012-12-28T14:47:26.257 回答