IOS Filter reprint, the original text see the first line link

Source: Internet
Author: User

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

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.