Reprinted from: http://blog.sina.com.cn/s/blog_5fb39f9101018gv7.html
Directly on the code:
////VIEWCONTROLLER.M//Blur image Processing////Created by wusiping on 16/1/28.//copyright©2016 year wusiping. All rights reserved.//#import "ViewController.h"#import<AssetsLibrary/AssetsLibrary.h>@interfaceViewcontroller () <UINavigationControllerDelegate,UIImagePickerControllerDelegate>@end@implementationviewcontroller{Cicontext*context; Cifilter*filter; Ciimage*beginimage;}- (void) viewdidload {[Super viewdidload]; //Get Picture PathNSString *filepath = [[NSBundle mainbundle] Pathforresource:@"Image"OfType:@"PNG"]; Nsurl*filenameandpath =[Nsurl Fileurlwithpath:filepath]; //Create a start picture based on the pathBeginimage =[Ciimage Imagewithcontentsofurl:filenameandpath]; Context=[Cicontext Contextwithoptions:nil]; //create filters, and output picturesFilter = [Cifilter filterwithname:@"Cisepiatone"Keysandvalues:kciinputimagekey, Beginimage,@"inputintensity", @0.8, nil]; Ciimage*outputimage =[Filter outputimage]; //Here you use a method in the context object to draw a cgimage that invokes the Createcgimage:fromrect in the context: and the ciimage provided can generate a cgimageref. Cgimageref cgimg =[Context Createcgimage:outputimage fromrect:[outputimage extent]; //below, you use UIImage + imagewithcgimage to create a uiimage from Cgimage. UIImage *newimage =[UIImage imagewithcgimage:cgimg]; Self.imageView.image=NewImage; //Finally, open the Cgimageref interface. Cgimage is a C interface, and even with arc, you need to do memory management yourself. Compile and run to ensure proper operation. cgimagerelease (CGIMG); [Self logallfilters]; }-(Ibaction) amountslidervaluechanged: (ID) Sender {floatSlidevalue =Self.amountSlider.value; [Filter setvalue:@ (Slidevalue) Forkey:@"inputintensity"]; Ciimage*outputimage =[Filter outputimage]; Cgimageref cgimg=[Context Createcgimage:outputimage fromrect:[outputimage extent]; UIImage*newimage =[UIImage imagewithcgimage:cgimg]; Self.imageView.image=NewImage; Cgimagerelease (cgimg);}-(Ibaction) Loadphoto: (ID) Sender {Uiimagepickercontroller*PICKERC =[[Uiimagepickercontroller alloc] init]; Pickerc.Delegate=Self ; [Self Presentviewcontroller:pickerc animated:yes completion:nil];}-(Ibaction) Savephoto: (ID) Sender {ciimage*savetosave =[Filter outputimage]; Cicontext*softwarecontext =[Cicontext contextwithoptions:@{kcicontextusesoftwarerenderer: @ (YES)}]; Cgimageref cgimg=[Softwarecontext createcgimage:savetosave fromrect:[savetosave extent]; Alassetslibrary* Library =[[Alassetslibrary alloc] init]; [Library writeimagetosavedphotosalbum:cgimg Metadata:[savetosave Properties] Completionblock:^ (Nsurl *asseturl, Nserror *error) {cgimagerelease (cgimg);}];}- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) Info {[self dismissviewcontrolleranimated:yes completion:nil]; UIImage*gotimage =[Info objectforkey:uiimagepickercontrolleroriginalimage]; Beginimage=[Ciimage ImageWithCGImage:gotImage.CGImage]; [Filter Setvalue:beginimage Forkey:kciinputimagekey]; [Self amountSliderValueChanged:self.amountSlider];}- (void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) Picker {[self dismissviewcontrolleranimated:yes completion:nil];}/** * Print all Filters*/-(void) logallfilters {Nsarray*properties =[Cifilter Filternamesincategory:kcicategorybuiltin]; NSLog (@"%@", properties); for(NSString *filternameinchproperties) {Cifilter*fltr =[Cifilter Filterwithname:filtername]; NSLog (@"%@", [fltr attributes]); }}@end
IOS Filter reprint, see text first line link