I am using AlamofireImage to download an image from my CDN however I would like to apply a custom filter (Grey Scale) to SOME of the images that are downloaded. Currently I am using a scrollView to show all available images and if an image has a particular attribute, apply the filter.
I am new to AlamofireImage so I don't know how to apply a custom filter.
I have applied
let imageFilter = BlurFilter(blurRadius: 10)
to the filter parameter so I know the actual filter process is working but can someone please help with creating a custom filter to apply grey scale to downloaded image?
Approach #1
Use Alamofireimage's "imageWithAppliedCoreImageFilter" UIImage extension. But for some reason they don't provide easy protocol access to this filter option, so let's create one...
Usage should be familiar to the Alamofireimage user:
If you're not happy with the CIColorMonochrome filter (I wasn't), here are some other options...
or
Here's a link to the complete list of available filters on the Apple dev site.
Approach #2
Find a custom filter, such as the top rated answer to What is the best Core Image filter to produce black and white effects?.
Then create a extension. Credit Shmidt and DerGote for the body of the code below.
and the struct...
And finally, Usage...