How to use Cifilter to add a variety of filters to the picture _2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.