3

写真から赤目効果を削除したいのですが、サンプルがありません。デモ コードまたはコード スニペットの作業を手伝ってくれる人はいますか?

ありがとう。

4

1 に答える 1

7

以下categoryの使用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

使用法:以下のサンプルコード

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

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

NYXImagesKit UIImage 拡張リンクを参照してください

于 2012-11-06T10:35:17.440 に答える