IOS coreimage Picture processing dynamic Rendering (filters)

Source: Internet
Author: User

//

Viewcontroller.m

Coreimageofdong

//

Created by 15/6/30.

Copyright (c) year Xindong. All rights reserved.

//

#import "ViewController.h"

#import <GLKit/GLKit.h>// need to import this library

@interface Viewcontroller ()

@ Property ( nonatomic strong ) Span style= "font-size:14px" >glkview *glkview; // buffer view ( similar to streaming Real-time change )

@property (nonatomic, strong) Cifilter *filter;

@property (nonatomic, strong) Ciimage *ciimage;

@property (nonatomic, strong) Cicontext *cicontext;

@end


@implementation Viewcontroller


-(void) Viewdidload {

[Super Viewdidload];

        

UIImage *showimage = [UIImage imagenamed:@ "demo1.jpg"];

CGRect rect = CGRectMake (0, 0, showImage.size.width, showImage.size.height);

// get context of opengles rendering

Eaglcontext *eagcontext = [[Eaglcontext alloc] initwithapi:keaglrenderingapiopengles2];

// Create a rendered buffer

Self.glkview = [[Glkview alloc] Initwithframe:rect Context:eagcontext];

[Self.glkview binddrawable]; // bind draw , otherwise it will start black screen

[Self.view AddSubview:self.glkView];

// Create a context for Coreimage

Self.cicontext = [Cicontext contextwitheaglcontext:eagcontext options:@{kcicontextworkingcolorspace: [NSNull NULL]}] ;

//Coreimage Related Settings

Self.ciimage = [[Ciimage alloc] initwithimage:showimage];

Self.filter = [Cifilter filterwithname:@ "Cisepiatone"];

[Self.filter setValue:self.ciImage Forkey:kciinputimagekey];

[Self.filter setvalue:@ (0) Forkey:kciinputintensitykey];

// start rendering

[Self.cicontext drawimage:[self.filter Valueforkey:kcioutputimagekey] Inrect:cgrectmake (0, 0, Self.glkView.drawableWidth, Self.glkView.drawableHeight) fromrect:[self.ciimage extent]];

[Self.glkview display];

// dynamic rendering

UISlider *slider = [[UISlider alloc] Initwithframe:cgrectmake (30, 500, 200, 10)];

Slider.minimumvalue = 0.F;

Slider.maximumvalue = 10.F;

[Slider addtarget:self action: @selector (Changecolorvalue:) forcontrolevents:uicontroleventvaluechanged];

[Self.view Addsubview:slider];

}

-(void) Changecolorvalue: (UISlider *) slider

{

[Self.filter setValue:self.ciImage Forkey:kciinputimagekey];

[Self.filter setvalue:@ (Slider.value) Forkey:kciinputintensitykey];

// start rendering

[Self.cicontext drawimage:[self.filter Valueforkey:kcioutputimagekey] Inrect:cgrectmake (0, 0, Self.glkView.drawableWidth, Self.glkView.drawableHeight) fromrect:[self.ciimage extent]];

[Self.glkview display];

}

IOS coreimage Picture processing dynamic Rendering (filters)

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.