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

发布于 2024-12-28 04:21:25 字数 2032 浏览 0 评论 0原文

我想要一张尽可能清晰的黑白图片,适用于 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];

亲切地

i want to have a picture black&white the most clear as possible, for an app iPad et iPhone.

i did many thing for that :

1 - i take my picture with iPad's or iPhone's camera.

2 - i apply my first filter == CIColorMonochrome == and i display to be sure if that work.
my first filter work well.

3 - i recover the result of my last filter and i use it to apply my new filter == CINoiseReduction == and i display it to be sure if that work too ! but this time it display nothing so i don't know why.

      //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];

cordially

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文