I\'m setting UImageViews within table cells using setImageWithUrl from the AFNetworking library, but I need the images to be greyscale... is there any way I can do this. I\'
I took the code from @Jesse Gumpo's example, above, but here it is as an interface.
@implementation UIImage ( Greyscale )
- (UIImage *)greyscaleImage
{
CIImage * beginImage = [ self CIImage ] ;
CIImage * evAdjustedCIImage = nil ;
{
CIFilter * filter = [ CIFilter filterWithName:@"CIColorControls"
keysAndValues:kCIInputImageKey, beginImage
, @"inputBrightness", @0.0
, @"inputContrast", @1.1
, @"inputSaturation", @0.0
, nil ] ;
evAdjustedCIImage = [ filter outputImage ] ;
}
CIImage * resultCIImage = nil ;
{
CIFilter * filter = [ CIFilter filterWithName:@"CIExposureAdjust"
keysAndValues:kCIInputImageKey, evAdjustedCIImage
, @"inputEV", @0.7
, nil ] ;
resultCIImage = [ filter outputImage ] ;
}
CIContext * context = [ CIContext contextWithOptions:nil ] ;
CGImageRef resultCGImage = [ context createCGImage:resultCIImage
fromRect:resultCIImage.extent ] ;
UIImage * result = [ UIImage imageWithCGImage:resultCGImage ] ;
CGImageRelease( resultCGImage ) ;
return result;
}
@end
Now you can just do this:
UIImage * downloadedImage = ... get from AFNetwork results ... ;
downloadedImage = [ downloadedImage greyscaleImage ] ;
... use 'downloadedImage' ...