What is the Core image and what?
The answer to this question is not very good, but in fact it is very simple. It must be Apple's API for image processing. Online all the big God have explained, but can see not much, my understanding is Photoshop filter, of course, in all kinds of beauty map software has this function, I mainly see how to use it
Second, what are the available filters for Core image?
127 values {[0] = "Ciaccordionfoldtransition" [1] = "Ciadditioncompositing" [2] = "Ciaffineclamp" [3] = "Ciaffinetile [4] = "Ciaffinetransform" [5] = "Ciareahistogram" [6] = "Ciazteccodegenerator" [7] = "Cibarsswipetransition" [8] = "Ciblendwithalphamask" [9] = "Ciblendwithmask" [ten] = "Cibloom" [One] = "Cibumpdistortion" [[] = "cibumpdistortionline Ar "[] =" Cicheckerboardgenerator "[+] =" Cicirclesplashdistortion "[] =" Cicircularscreen "[+] =" Cicode128barc Odegenerator "[] =" Cicolorblendmode "[] =" Cicolorburnblendmode "[+] =" Cicolorclamp "[[] =" Cicolorcontrols " [+] = "Cicolorcrosspolynomial" [[] = "Cicolorcube" [] = "Cicolorcubewithcolorspace" [[] = "Cicolordodgeblendmode" [] = "Cicolorinvert" [[] = "Cicolormap" [+] = "Cicolormatrix" [[] = "Cicolormonochrome" [] = "cicolorpolynomia L "[+] =" Cicolorposterize "[+] =" Ciconstantcolorgenerator "[[+] =" ciconvolution3x3 "["] = "ciconvolution5x5" [3 4] = "Ciconvolution9horiZontal "[+] =" Ciconvolution9vertical "[[] =" Cicopymachinetransition "[PNS] =" Cicrop "[] =" Cidarkenblendmode "[ [Cidifferenceblendmode] = "Cidisintegratewithmasktransition" [[+] = "Cidissolvetransition" ["] =" cidivideb Lendmode "[[] =" Cidotscreen "[] [] =" Cieightfoldreflectedtile "[[] =" Ciexclusionblendmode "[+] =" Ciexposureadjus T "[+] =" Cifalsecolor "[[] =" Ciflashtransition "["] = "Cifourfoldreflectedtile" [[] = "Cifourfoldrotatedtile" [ [Cifourfoldtranslatedtile] = "Cigammaadjust" [+] = "Cigaussianblur" [si] = "cigaussiangradient" [+] = "CI Glassdistortion "[[]] =" ciglidereflectedtile "[Page] =" Cigloom "[[+] =" Cihardlightblendmode "[+] =" Cihatchedscreen " [Cihighlightshadowadjust] = "Cihistogramdisplayfilter" [max] = "Ciholedistortion" [[+] = "Cihueadjust" [6 4] = "Cihueblendmode" [[+] = "Cilanczosscaletransform" [[[]] = "Cilightenblendmode" [[+] = "Cilighttunnel" [[] [] [] = "Cili Nearburnblendmode "[69] = "Cilineardodgeblendmode" [[] = "Cilineargradient" ["] =" Cilineartosrgbtonecurve "[[] [] =" Cilinescreen "["] = "C Iluminosityblendmode "["] = "Cimasktoalpha" [[] [] = "Cimaximumcomponent" ["] =" cimaximumcompositing "[All] =" Ciminim Umcomponent "[[+] =" ciminimumcompositing "[+] =" Cimodtransition "[[] =" Cimultiplyblendmode "[Bayi] =" cimultiplycom Positing "[[+] =" Cioverlayblendmode "["] = "ciperspectivecorrection" [+] = "Ciphotoeffectchrome" ["] =" Ciphotoeff Ectfade "[[+] =" Ciphotoeffectinstant "[[]] =" Ciphotoeffectmono "[["] = "Ciphotoeffectnoir" [[]] = "Ciphotoeffectproc ESS "[All] =" ciphotoeffecttonal "["] = "Ciphotoeffecttransfer" [[]] = "Cipinchdistortion" ["] =" Cipinlightblendmode [94] = "Cipixellate" [[] [] = "Ciqrcodegenerator" [[] [] = "Ciradialgradient" [] = "Cirandomgenerator" [98] = "Cisatu Rationblendmode "["] = "Ciscreenblendmode" [+] = "Cisepiatone" [101] = "Cisharpenluminance" [102] = "Cisixfoldrefle Ctedtile "[103] =" CisiXfoldrotatedtile "[104] =" Cismoothlineargradient "[[+] =" Cisoftlightblendmode "[106] =" Cisourceatopcompositing "[1 [] = "cisourceincompositing" [108] = "cisourceoutcompositing" [109] = "cisourceovercompositing" [+] = "Cisrgbtonecur Vetolinear "[111] =" Cistarshinegenerator "["] = "Cistraightenfilter" [113] = "Cistripesgenerator" [All] = "Cisubtra Ctblendmode "[[+] =" Ciswipetransition "["] = "Citemperatureandtint" [117] = "Citonecurve" [118] = "Citrianglekalei Doscope "[119] =" Citwelvefoldreflectedtile "[+] =" Citwirldistortion "[121] =" Ciunsharpmask "[122] =" Civibrance " [123] = "Civignette" [124] = "Civignetteeffect" ["] =" civortexdistortion "[126] =" Ciwhitepointadjust "}
View Code
For now, there are 127, and I'll find out for you, you can use it yourself. Request the name of the filter to the Kcicategorybuiltin category of core image
Let Filternames = Cifilter.filternamesincategory (Kcicategorybuiltin) as [String]
Third, the basic use of filters
3.1 Create a filter (using the filter name, the initialization method passed to the filter Cifilter is created successfully)
Let Blurfilter=cifilter (named: "Cigaussianblur")
3.2 Setting Filter Parameters
Filter parameters (such as creating a blur filter above) are usually set by KVC, and the following code sets the blur radius parameter of the blur filter
Blurfilter.setvalue (12.0 forkey: "Inputradius")
3.3 Creating an image using filters
Core image requires that the image used for the filter is of the Ciimage type, different from our usual uiimage, but also easily created from UIImage, with a single line of code to handle
Let Inputimage=ciimage (Image:sourceImageView.image)
3.4 Apply a filter to an image (it is actually a very important property to set the filter: Inputimage)
Blurfilter.setvalue (Inputimage, Forkey: "Inputimage")
3.5 Get a picture of a filter processed
The processed picture is in the current filter rendering context, so you must first get the current context, we basics
Let Cicontext=cicontext (Options:nil)
From the current context to get the output of the picture, of course, this is also a ciimage type of diagram, the parameters passed in is the filter properties: Outputimage
Let Cgimage = Cicontext.createcgimage (Blurfilter. Outputimage, FromRect:inputImage.extent ())
From this ciimage is also a code to get familiar with our UIImage
Resultimageview.image=uiimage (Cgimage:cgimage)
Get the results straight slice
The obvious blur effect comes out ... Clap your hands, don't be distracted.
————————————————————————————————————————————————————————————————————————
A picture is never just a filter effect, we can create multiple filters to make a chain that renders a filter, but note that the Inputimage property of each filter is the output property of the previous filter: Inputimage, on top of the little Kitty Blur, I'm going to change it, Let the original image not only Gaussian blur, add a monochrome filter, add a vignette filter
Create an input image let Inputimage=ciimage (image:sourceImageView.image)//Build a filter chart let Sepiacolor=cicolor (red: 0.6, green:0.65, blue:0.54) let Monochromefilter=cifilter (name: "Cicolormonochrome", withinputparameters:["InputC Olor ": Sepiacolor," inputintensity ": 1.0]) Monochromefilter.setvalue (inputimage, Forkey:" Inputimage ") Let Blurfilter=cifilter (name: "Cigaussianblur") blurfilter.setvalue (3.0, Forkey: "Inputradius") Blur Filter.setvalue (Monochromefilter.outputimage, Forkey: "Inputimage") Let Vignetterfilter=cifilter (name: "CIVigne Tte ", withinputparameters:[" Inputradius ": 1.75," inputintensity ": 1.0]) Vignetterfilter.setvalue ( Blurfilter.outputimage, Forkey: "Inputimage") let Outputimage=vignetterfilter.outputimage// Get a filter processed picture let Cicontext=cicontext (Options:nil) Let Cgimage=cicontext.createcgimage (Outputimage, Fromrect : Inputimage.extent ()) Resultimageview. Image=uiimage (Cgimage:cgimage)
View Code
You can see the first monochrome filter Monochromefilter's inputimage is the original image: Monochromefilter.setvalue (inputimage, Forkey: "Inputimage")
The second Gaussian Blur filter Blurfilter Inputimage is the output of the previous filter outputImage:blurFilter.setValue (Monochromefilter.outputimage, Forkey: " Inputimage ")
The third vignette of the filter Vignetterfilter Inputimage is the output of the previous filter outputImage:vignetterFilter.setValue (Blurfilter.outputimage, Forkey: "Inputimage")
You can also see that the properties of the filter are set up at the time of creation.
Let Vignetterfilter=cifilter (name: "Civignette", withinputparameters:["Inputradius": 1.75, "inputintensity": 1.0])
Finally attach three filter overlay effect, the specific effect can vary depending on the parameters
To make your own beauty 美图秀秀 ...
Core Image make your own beauty 美图秀秀