Use of the iOS development filter

Source: Internet
Author: User

First, the content and effect of the filter is more and more complex, the learning filter needs tips as follows: Two output statements resolve Filter Property selection issues:
  • 1. What effects are included in the query effect category?
    Hold command, click Cifilter to enter the interface file to find line 128th-148 rows are all effect categories
  • 2. Select one of the classified copies
    NSLog, [Cifilter filternamesincategory: The classification just copied]; ---Print out a copy of all the effects that this category contains and select one of the effects
  • 3. What properties can be set in the effect that the query uses (KVC) attributes
    NSLog, [cifilter filterwithname: Just copy Select one of the effects].attributes, get this filter all the properties you can set two, learn about filters related Introduction
    • 1. Introduction to the framework
      (1) Coreimage
      (2) is an image frame it uses the shader to process the image based on the underlying OpenGL top layer creation
      (3) It leverages the GPU to process images based on hardware acceleration
      (4) There are many filters in the Coreimage
      (5) They can give a single image or video frame multiple visual effects filter chain
      (6) and the filter can be joined together to form a filter chain to overlay the filter effect to process the image.
  • 2. Introduction to Classes
    (1) Ciimage: The class that holds the image data cgimageref-> the data in the image
    (2). Cifilter: Class of filter Class picture properties for detailed processing it operates on all pixels using key-value (KVC) to set
    (3). Cicontext: Context is an image that implements an image processing specific object--filter object output is not an image that needs to be merged with the context of the image processing after the image is synthesized
  • 3. Introduction to the effect
  • By effect Category:
    Kcicategorydistortioneffect distort effects, such as bump, rotation, hole
    Kcicategorygeometryadjustment geometry open adjustment, such as affine transformation, flat-cut, perspective conversion
    Kcicategorycompositeoperation merge, such as source over, minimize, source on top (source atop), color blending mode
    Kcicategoryhalftoneeffect halftone effects, such as screens, line screens, hatched
    Kcicategorycoloradjustment color adjustment, such as gamma adjustment, white point adjustment, exposure
    Kcicategorycoloreffect color effects, such as tonal adjustment, posterize
    Kcicategorytransition conversion between images, such as dissolve, disintegrate with mask, swipe
    Kcicategorytileeffect tile effects, such as parallelogram, triangle
    Kcicategorygenerator image generators, such as stripes, constant color, checkerboard
    Kcicategorygradient gradients, such as axial gradients, affine gradients, Gaussian gradients
    Kcicategorystylize stylized, such as pixelated, crystalline
    Kcicategorysharpen Sharpen, Glow
  • Kcicategoryblur Blur, such as Gaussian blur, focus Blur, motion blur

    • Categories by usage:
      Kcicategorystillimage for still images
      Kcicategoryvideo for Video
      Kcicategoryinterlaced for interlaced images
      Kcicategorynonsquarepixels for non-rectangular pixels
      Kcicategoryhighdynamicrange for HDR

      Third, the use of steps

      1. Example Ciimage, UIImage, Cgimageref, Ciimage
      2. Create the Cifilter filter and set the properties for the filter (KVC)
      3. Create a Cicontext context
      4. Initialize a cgimageref output Picture object merge Filter output image
      5. Assign to UIImage object for display
      6. If you want to use a filter chain, you can add effects again

      四、一个 Instance resolution filter filter Chain save picture

      code example:

      #import "ViewController.h"//macro Definition screen width # screen_width cgrectgetwidth ([UIScreen mainscreen].bounds)//    Note Hang up Agent @interface Viewcontroller () <uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate>{  Uiimageview *myimageview;//receive a view of a picture UIButton *photobutton;//Select a picture from a local album button UIButton *filterbutton;//Add a filter button UIButton   *savebutton;//Button saved to local album after filter} @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload];//removes the height of the navigation bar Self.edgesforextendedlayout = uirectedgenone;//Set background color Self.view.backgroundColor = [uicolor greencolor];//Create button Nsarray   *titlebuttonlist = @[@ "Photo", @ "Filter", @ "save"]; for (int i=0; i<titlebuttonlist.count; i++) {UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];but Ton.frame = CGRectMake (20+80*i, 20, 60, 40); [Button settitle:titlebuttonlist[i] Forstate:uicontrolstatenormal];button.tag = ten +i; [Button Settitlecolor:[uicolor Blackcolor] Forstate:uicontrolstatenormal];button.backgroundcolor = [UIColor Cyancolor];       [Self.view Addsubview:button];       }//Initialize picture view Myimageview = [[Uiimageview alloc]initwithframe:cgrectmake (SCREEN_WIDTH-40, 300)];       Myimageview.backgroundcolor = [Uicolor Cyancolor];       [Self.view Addsubview:myimageview];       Photobutton = [Self.view viewwithtag:10];       Filterbutton = [Self.view viewwithtag:11];   Savebutton = [Self.view viewwithtag:12]; Add a trigger event to three buttons [Photobutton addtarget:self action: @selector (photoaction:) Forcontrolevents:uicontroleventtouchupi   Nside]; Filter button [Filterbutton addtarget:self action: @selector (filteraction:) forcontrolevents:uicontroleventtouchupinside   ]; button to save the picture after the filter [Savebutton addtarget:self action: @selector (saveaction:) forcontrolevents:uicontroleventtouchupinside   ]; }//Select Picture-(void) Photoaction: (UIButton *) sender{Uiimagepickercontroller *pickercontroller = [[Uiimagepickercont       Roller Alloc]init];       Pickercontroller.delegate = self; [Self Presentviewcontroller:Pickercontroller Animated:yes Completion:nil]; }//Put the picture on the picture View-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (       Nsdictionary<nsstring *,id> *) info{UIImage *image = Info[uiimagepickercontrolleroriginalimage];       Myimageview.image = image;   [Self dismissviewcontrolleranimated:yes completion:nil]; }//Filter button trigger Method-(void) FilterAction: (UIButton *) sender{//1. SOURCE graph Ciimage *inputimage = [Ciimage imagewithcgim   Age:myImageView.image.CGImage];   2. Filter Cifilter *filter = [Cifilter filterwithname:@ "Cicolormonochrome"]; NSLog (@ "%@", [Cifilter filternamesincategory:kcicategorycoloreffect]);//note here the important role of two output statements NSLog (@ "%@", Filter.att       Ributes);       [Filter Setvalue:inputimage Forkey:kciinputimagekey];       [Filter Setvalue:[cicolor colorwithred:1.000 green:0.165 blue:0.176 alpha:1.000] forkey:kciinputcolorkey];       Ciimage *outimage = filter.outputimage; [Self addfilterlinkerwithimage:Outimage]; }//Add filters again to form a filter chain-(void) Addfilterlinkerwithimage: (Ciimage *) image{cifilter *filter = [Cifilter filterwithname       : @ "Cisepiatone"];       [Filter Setvalue:image Forkey:kciinputimagekey];   [Filter setvalue:@ (0.5) Forkey:kciinputintensitykey];       Create the context here to combine filters and pictures cicontext *context = [Cicontext Contextwithoptions:nil];       Cgimageref resultimage = [context createCGImage:filter.outputImage fromRect:filter.outputImage.extent];   Myimageview.image = [UIImage imagewithcgimage:resultimage];  }//Save the image of the filter to the local album-(void) Saveaction: (UIButton *) sender{uiimagewritetosavedphotosalbum (Myimageview.image, Self,   @selector (image:didFinishSavingWithError:contextInfo:), nil); }//Save method for successful call-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) ContextInfo   {NSLog (@ "Save succeeded"); } @end

    • The 2015 Apple WWDC conference brought some good news to developers fascinated by core Image filters. Not only are there a number of filters, such as the blur filter and the convolution filter supported by metalperformanceshaders, that show some amazing performance gains, but Apple has already implemented the same performance available image filters on both iOS and OSX platforms.

      This also gives iOS a new image filter so I can't wait to add it to my own nodality application. It also means that code and functionality can be shared on classes and devices, and I'm already imagining a desktop version of nodality.

      So, these new filters are God's horse stuff? Let's just say, Cifilter. This class has a class method Filternamesincategories () that returns an array containing all the available filters. Here's a quick look at the difference between IOS8 and 9:

      • Ciareaaverage -Returns a single-pixel image that contains the average color within a piece of color area.

      • Ciareamaximum -Returns a single-pixel image that contains the largest color component in a color area.

      • Ciareamaximumalpha-Returns a single-pixel image that contains the color vector for the maximum transparency in the color area.

      • Ciareaminimum -Returns a single-pixel image that contains the smallest color component in the color area.

      • Ciareaminimumalpha -Returns a single-pixel image that contains the color vector of the minimum transparency within the color area.

      • Ciboxblur-blurs the image within a rectangle.

      • Cicircularwrap-surround the image with a transparent circle.

      • Cicmykhalftone -Creates a color that makes the source image semi-tonal, using cyan, magenta, yellow, and ink on white pages.

      • Cicolumnaverage -Returns an image with a height of 1 pixels, containing the average color of each scanned column.

      • Cicomiceffect -Outline (image) edges like comic books and apply halftone effects.

      • ciconvolution7x7 -Adjusts the pixel values with a 7x7 rotation matrix.

      • Cicrystallize -Creates a polygon color block by pooling the color values of the source pixels.

      • Cidepthoffield -simulates a scene in-depth effect.

      • Cidiscblur-blurs the image within a disc shape.

      • Cidisplacementdistortion -Applies the grayscale value of the second image to the first image.

      • Cidroste -Draws a part of the image recursively, using a similar m.c. Escher drawing method.

      • Ciedges -Displays the edges of the image in color.

      • Ciedgework -produces an image of a black-and-white style similar to a wood cut.

      • Ciglasslozenge -Creates a diamond filter and distorts the image of the filter position.

      • Ciheightfieldfrommask -produces a continuous three-dimensional object, a loft-shaped gray field.

      • Cihexagonalpixellate -Maps the color hexagonal image with the pixels that are replaced.

      • Cikaleidoscope -Creates a colorful image from the source images by 12-way symmetry.

      • Cilenticularhalogenerator -simulates the flash effect.

      • Cilineoverlay -Creates a sketch that outlines the edges of the image in black.

      • Cimedianfilter -Calculates the average of a set of neighboring pixels, and then replaces the value of each pixel with an average.

      • Cinoisereduction-reduces noise by reducing the limits of noise.

      • Cioptile -Splits the image first, imposes some specified scaling and rotation, and then mosaics the image, forming the artistic expression.

      • Cipagecurltransition -Convert from one image to another using the flip effect, and the new image is displayed after the scroll is rolled.

      • Cipagecurlwithshadowtransition -Convert from one image to another using the flip effect, and the new image is displayed after the scroll is rolled.

      • Ciparallelogramtile -Displays an image within the parallelogram.

      • Cipassthroughcolor

      • Cipassthroughgeom

      • Cipdf417barcodegenerator

      • Cipointillize-Renders a pointillistic-style source image.

      • Cirippletransition-Image Create a circular wave expands outward from the center point, displaying a new image in the waveform.

      • Cirowaverage -Returns a 1-pixel high image that contains the average color of each row of scans.

      • Cishadedmaterial-Produces a shadow image from a height field.

      • Cispotcolor -Replaces the color range with a color dot.

      • Cispotlight -The image is rendered using a directional spotlight effect.

      • Cistretchcrop -The image is stretched and or clipped to fit the target dimension.

      • Cisunbeamsgenerator -The image shows the effect of sun exposure.

      • Citoruslensdistortion-Creates a ring filter and distorts the image of the lens position.

      • Citriangletile-A triangular portion of the captured image is mapped to a triangle area and then tiled to show.

Use of the iOS development filter

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.