2016-07-28 74 views
1

要添加紅眼校正效果,我曾跟隨這個鏈接:紅眼校正

How to remove red eye from image in iPhone?

通過吊艙上面安裝庫。在我的課程中添加了以下代碼。

UIImage *redEyeImage = [UIImage imageNamed:@"Userimage"]; 

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

但我沒有得到所需的輸出。有什麼我失蹤?或者是否有其他圖書館來實施這個概念。請建議。

謝謝!

+0

確定圖像名稱輸入正確嗎?你能告訴我if語句是否執行嗎? – kabiroberai

+0

是的,如果語句正在執行。但結果仍然相同 –

回答

0

您可以設置在線路斷點都if語句,然後之後運行你的應用程序,看看他們正在打(也許redEyeImage不存在或newRemovedRedEyeImage沒有。

另一種簡單的方式來檢查:

UIImage *redEyeImage; 
UIImage *newRemovedRedEyeImage; 

redEyeImage = [UIImage imageNamed:@"Userimage"]; 

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

NSLog(@"redEyeImage: %@", (redEyeImage != nil ? @"exists" : @"nil")); 
NSLog(@"newRemovedRedEyeImage: %@", (newRemovedRedEyeImage != nil ? @"exists" : @"nil")); 

然後運行這一點,看看這兩個日誌底部打印

+0

都存在 –

0

最後我解決了這個問題,用下面的代碼:

UIImage *img = [UIImage imageNamed:@"images.png"]; 
CIImage *image = [[CIImage alloc]initWithImage:img]; 
NSLog(@"after ciimage: %@", kCIImageAutoAdjustEnhance); 
NSDictionary *options = [NSDictionary dictionaryWithObject:@"NO" forKey:kCIImageAutoAdjustEnhance]; 
NSLog(@"options: %@", options); 
NSArray *adjustments = [image autoAdjustmentFiltersWithOptions:options]; 
NSLog(@"adjustments: %@ ", adjustments); 

for (CIFilter * filter in adjustments) 
{ 
    [filter setValue:image forKey:kCIInputImageKey]; 
    image = filter.outputImage; 
} 
CIContext *context = [CIContext contextWithOptions:nil]; 
CGImageRef cgImage = [context createCGImage:image fromRect:image.extent]; 
UIImage *enhancedImage = [[UIImage alloc] initWithCGImage:cgImage]; 
CGImageRelease(cgImage); 
self.img.image = enhancedImage;