iphone - 核心图像过滤器应用

标签 iphone objective-c ios ios5 core-image

我如何应用我应用的 CIToneCurve 滤镜

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

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

inputImage A CIImage class whose display name is Image.

inputPoint0 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 1. Default value: [0, 0] Identity: [0, 0]

inputPoint1 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 2l. Default value: [0.25, 0.25] Identity: [0.25, 0.25]

inputPoint2 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 3l. Default value: [0.5, 0.5] Identity: [0.5, 0.5]

inputPoint3 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 4. Default value: [0.75, 0.75] Identity: [0.75, 0.75]

inputPoint4 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 5. Default value: [1, 1] Identity: [1, 1]

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

最佳答案

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

- (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 中的结果不完全一样这是因为我的图像是局部图像并且颜色分布不同。相似但不完全相同。所以应用完全相同的曲线不会给出完全相同的结果。

希望对你有帮助

关于iphone - 核心图像过滤器应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9818300/

相关文章:

iphone - 如何在 UIDatePicker 中记住并加载选定的日期?

ios - 媒体未在 iOS phonegap 1.5 应用程序中播放

ios - Core Data Fetch Request 在模拟器上运行,但在设备上不运行

iphone - setFetchBatchSize 的作用是什么?

iphone - UITableView中的UILabel设置大小

iphone - ASIHTTPRequest 和 http header

iphone - 使用渐变图层作为背景,同时还使用 drawRect : 在上下文中进行绘制

ios - 检测媒体内容是否从 WKWebView 开始播放

objective-c - 如何居中 NSSegmentedControl

iOS swift : Rotate and Scale UIView without resizing