How to remove red eye from image in iPhone?

2020-02-06 09:57发布

I want to remove red eye effect form photo but not get any sample can any one help me with working demo code or code snippet?

Thanks.

1条回答
来,给爷笑一个
2楼-- · 2020-02-06 10:41

Use below category of UIImage :

@interface UIImage (Utitlities)
  -(UIImage*)redEyeCorrection;
@end

@implementation UIImage (Utitlities)
  -(UIImage*)redEyeCorrection
  {
    CIImage *ciImage = [[CIImage alloc] initWithCGImage:self.CGImage];

    // Get the filters and apply them to the image
    NSArray* filters = [ciImage autoAdjustmentFiltersWithOptions:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:kCIImageAutoAdjustEnhance]];
    for (CIFilter* filter in filters)
    {
      [filter setValue:ciImage forKey:kCIInputImageKey];
      ciImage = filter.outputImage;
    }

    // Create the corrected image
    CIContext* ctx = [CIContext contextWithOptions:nil];
    CGImageRef cgImage = [ctx createCGImage:ciImage fromRect:[ciImage extent]];
    UIImage* final = [UIImage imageWithCGImage:cgImage];
    CGImageRelease(cgImage);
    return final;
  }
@end

Usage: Sample code given below

 UIImage *redEyeImage = [UIImage imageNamed:@"redEye.jpg"];

if (redEyeImage) {
    UIImage *newRemovedRedEyeImage = [redEyeImage redEyeCorrection];
    if (newRemovedRedEyeImage) {
        imgView.image = newRemovedRedEyeImage;
    }
}

Refer NYXImagesKit UIImage Enhancing link

查看更多
登录 后发表回答