How to remove red eye from image in iPhone?

前端 未结 1 682
一生所求
一生所求 2020-12-11 10:06

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条回答
  • 2020-12-11 10:30

    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

    0 讨论(0)
提交回复
热议问题