核心图像过滤器适用

时间:2012-03-22 07:51:01

标签: iphone objective-c ios ios5 core-image

我如何应用我应用的CIToneCurve过滤器

  filter= [CIFilter filterWithName:@"CIScreenBlendMode"];
     [filter setValue:beginImage1 forKey:kCIInputImageKey];
     [filter setValue:beginImage forKey:@"inputBackgroundImage"];

使用此方法的不同过滤器现在我想应用CIToneCurve如何应用这些参数

  

inputImage       一个CIImage类,其显示名称为Image。

     

inputPoint0       一个CIVector类,其属性类型为CIAttributeTypeOffset,其显示名称为Point 1.默认值:[0,0]标识:[0,0]

     

inputPoint1   一个CIVector类,其属性类型为CIAttributeTypeOffset,其显示名称为Point 2l。默认值:[0.25,0.25]标识:[0.25,0.25]

     

inputPoint2   一个CIVector类,其属性类型为CIAttributeTypeOffset,其显示名称为Point 3l。默认值:[0.5,0.5]标识:[0.5,0.5]

     

inputPoint3   一个CIVector类,其属性类型为CIAttributeTypeOffset,其显示名称为Point 4.默认值:[0.75,0.75]标识:[0.75,0.75]

     

inputPoint4   一个CIVector类,其属性类型为CIAttributeTypeOffset,其显示名称为Point 5.默认值:[1,1]标识:[1,1]

我写这些但我的应用程序崩溃而没有给出任何错误

1 个答案:

答案 0 :(得分:8)

每个过滤器都接受不同类型的参数,但一旦你习惯了它们就很容易了。 你没有发布你得到的错误,但这对我有用:

- (void)doCIToneCurveFilter
{
    // Set an appropriate image. A bit dark so we see the results clearer
    // This image is being taken from http://photo.tutsplus.com/tutorials/post-processing/adobe-camera-raw-for-beginners-tone-curve/
    imageView.image = [UIImage imageNamed:@"turtles"];
    imageView.frame = CGRectMake(0, 0, imageView.image.size.width*0.7, imageView.image.size.height*0.7); // shrank this a bit 2 images fit on screen

    // Make the input image recipe
    CIImage *inputImage = [CIImage imageWithCGImage:imageView.image.CGImage];

    // Make tone filter filter
    // See mentioned link for visual reference
    CIFilter *toneCurveFilter = [CIFilter filterWithName:@"CIToneCurve"];
    [toneCurveFilter setDefaults];
    [toneCurveFilter setValue:inputImage forKey:kCIInputImageKey];
    [toneCurveFilter setValue:[CIVector vectorWithX:0.0  Y:0.0] forKey:@"inputPoint0"]; // default
    [toneCurveFilter setValue:[CIVector vectorWithX:0.27 Y:0.26] forKey:@"inputPoint1"]; 
    [toneCurveFilter setValue:[CIVector vectorWithX:0.5  Y:0.80] forKey:@"inputPoint2"];
    [toneCurveFilter setValue:[CIVector vectorWithX:0.7  Y:1.0] forKey:@"inputPoint3"];
    [toneCurveFilter setValue:[CIVector vectorWithX:1.0  Y:1.0] forKey:@"inputPoint4"]; // default

    // Get the output image recipe
    CIImage *outputImage = [toneCurveFilter outputImage];

    // Create the context and instruct CoreImage to draw the output image recipe into a CGImage
    CIContext *context = [CIContext contextWithOptions:nil];
    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];

    // Draw the image in screen
    UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:cgimg]];
    CGRect f = imageView2.frame;
    f.origin.y = CGRectGetMaxY(imageView.frame);
    f.size.width = imageView.frame.size.width;
    f.size.height = imageView.frame.size.height;
    imageView2.frame = f;

    [self.view addSubview:imageView2];
}

这就是结果:

Result CIToneCurve

我使用的图像来自here,在那里你可以找到我在这个例子中近似的曲线:

curve

PS:如果你想知道为什么我的结果图像与the link中的结果看起来不完全相同,那是因为我的图像是部分图像,颜色分布不同。相似但不完全一样。因此,应用完全相同的曲线将不会给出完全相同的结果。

我希望它有所帮助