xcode5:如何使用内置的Core Image过滤器?

时间:2014-04-07 14:23:34

标签: core-image ciimage

我是开发iOS应用程序的新手。 我想在我的应用程序中使用内置的核心图像过滤器。但我不知道如何使用它们。我已经创建了" CISephiaTon"过滤。现在我想创建" CIPhotoEffectTransfer"过滤。但我不知道我怎么能这样做=( 有没有人知道一个好的教程或者可以给我一个在xcode 5中应用核心图像过滤器?

这是我要添加的过滤器。有人可以给我这个过滤器的代码吗?

希望有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

请注意以下代码......

//First create a CIImage
UIImageOrientation originalOrientation = origim.imageOrientation;
data3 = UIImagePNGRepresentation(origim);
CIImage *result = [CIImage imageWithData:data3];

//Create the context
CIContext *context = [CIContext contextWithOptions:nil];

Apply the filter
CIFilter *colorControlsFilter = [CIFilter filterWithName:@"CIColorControls"];
    [colorControlsFilter setDefaults];
    [colorControlsFilter setValue:result forKey:@"inputImage"];
    [colorControlsFilter setValue:[NSNumber numberWithFloat:slySlider1.value] forKey:@"inputSaturation"];
    result = [colorControlsFilter valueForKey: @"outputImage"];

//Create CGImage with the original orientation, CIImage, and context.
CGImageRef imgRef = [context createCGImage:result fromRect:result.extent];

    //Create the new UIImage from CGImage
    theimage.image = [[UIImage alloc] initWithCGImage:imgRef scale:1.0 orientation:originalOrientation];
    //Release CGImageRef
    CGImageRelease(imgRef);

好教程Beginning Core Image