我想从照片中删除红眼效果,但没有得到任何样本,有人可以帮助我制作演示代码或代码片段吗?
谢谢。
最佳答案
使用以下 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 Enhancing 链接
关于iphone - 如何从 iPhone 中的图像中去除红眼?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13249013/