The previous article said how to find a filter to use and probably how to find ...
Here's how to add a filter effect to a picture in detail. Before the preparation work ...
。
1. After finding the filter name you want to use. Need to know what the parameters of this filter need.
。
For example with
The print here is all the parameters of the current filter.
。
。 For example with
In Ciattributefiltername, the following parameters are required to set the properties:
。 Here are the 3 Inputcolor, Inputimage and Inputintensity
The ciattributeclass indicates what type of value this attribute requires.
The methods for setting properties are as follows:
Set properties by using the SetValue Forkey method ... This Key is the K + attribute name +key
After the property is set, you are able to output!.
。 Here is a demonstration using the Cicolormonochrome filter directly.
-(UIImage *) ImageFilter: (UIImage *) Photo Value: (float) value{ cicontext *context = [Cicontext contextwithoptions: NIL]; 1 ciimage *image = [[Ciimage alloc] initwithimage:photo]; 2 cifilter *filter = [Cifilter filterwithname:@ "Cicolormonochrome"]; 3 NSLog (@ "%@", [Filter Attributes]); [Filter Setvalue:image Forkey:kciinputimagekey]; [Filter Setvalue:[cicolor colorwithred:100/255 green:0.4 blue:1] forkey:kciinputcolorkey]; Ciimage *result = [Filter Valueforkey:kcioutputimagekey]; 4 cgrect extent = [result extent]; Cgimageref cgimage = [Context Createcgimage:result fromrect:extent];//5 return [UIImage imagewithcgimage:cgimage ];}
So far.
。 The return uiimage is a picture of the filter superimposed on it.
How to use Cifilter to add a variety of filters to a picture _2