当我尝试使用两个CIFilter时出现一些问题

时间:2012-01-18 15:03:07

标签: objective-c cocoa filter core-graphics core-image

对于iPad和iPhone应用程序,我希望尽可能使用最清晰的黑白照片。

我做了很多事情:

1 - 我用iPad或iPhone的相机拍照。

2 - 我应用我的第一个过滤器== CIColorMonochrome ==并显示以确定是否有效。 我的第一个过滤器工作得很好。

3 - 我恢复了我最后一个过滤器的结果,并使用它来应用我的新过滤器== CINoiseReduction ==并且我显示它以确定是否也有效!但这次它什么都没显示,所以我不知道为什么。

      //CIColorMonochrome
    CIFilter * monochromeFilter;
    monochromeFilter = [CIFilter filterWithName:@"CIColorMonochrome"];
    [monochromeFilter setValue:beginImage forKey:@"inputImage"];

    //Red Green Blue Alpha
    [monochromeFilter setValue:[CIColor colorWithString:@"255 255 255 1.0"] forKey:@"inputColor"];

    [monochromeFilter setValue:[NSNumber numberWithFloat:1] forKey:@"inputIntensity"];
    CIImage* monochromeImage = [monochromeFilter valueForKey:@"outputImage"];
    CIImage* outputImage = monochromeImage;

    //---===---

    CIFilter* noiseReductionFilter = [CIFilter filterWithName:@"CINoiseReduction"];

    //[noiseReductionFilter setDefaults];

    [noiseReductionFilter setValue:outputImage forKey:@"inputImage"];
    [noiseReductionFilter setValue:[NSNumber numberWithFloat:0.2] forKey:@"inputNoiseLevel"];
    [noiseReductionFilter setValue:[NSNumber numberWithFloat:0.40] forKey:@"inputSharpness"];
    [noiseReductionFilter retain];

    CIImage* noiseReductionImage = [noiseReductionFilter valueForKey:@"outputImage"];

    // ---===---
    outputImage = noiseReductionImage;

    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[beginImage extent]];
    UIImage* newImg = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);

    [imageView removeFromSuperview];

    CGRect imageFrame = [imageView frame];

    [imageView release];

   // [self noiseReduction:newImg];

    imageView = [[UIImageView alloc]initWithImage:newImg]; 
    NSLog(@"%@ ===---=== " ,[self noiseReduction:newImg]);
    if (flag == 0)
        [imageView setFrame:imageFrame]; NSLog(@"setFrame image");

    NSLog(@"%@ ==== ", imageView);

    [[self view]addSubview:imageView];

亲切