[翻译] CoreImage-with-EAGLContext

CoreImage-with-EAGLContext

[翻译] CoreImage-with-EAGLContext

https://github.com/anaglik/CoreImage-with-EAGLContext

 

Simple example of drawing manipulated image to CIContext based on EAGLContext. This setup is recomended when applicaion needs Real-Time performance.(image is never copied to CPU memory).

一个简单的例子,在EAGLContext上下文中将被操作的图片绘制进CIContext。当你的应用需要实时变换图片的时候,建议你这么使用(图片永远不会被拷贝进内存当中)。

 

In this example I am using "CIMaskToAlpha" filter to replace background color of image below with color of main view.

这个例子中,我使用了CIMaskToAlpah滤镜,将下面图片的背景颜色替换成主view上背景颜色。

[翻译] CoreImage-with-EAGLContext

 

Result Image looks like this :

结果如下所示:

[翻译] CoreImage-with-EAGLContext

 

 

附录:

“UIImage+Blur.h” + “UIImage+Blur.m”

//

//  UIImage+Blur.h

//

//  Created by Luke on 13-9-3.

//  Copyright (c) 2013年 LukeCheng. All rights reserved.

//



#import <UIKit/UIKit.h>



@interface UIImage (Blur)



- (UIImage *)blur:(CGFloat)radius;



- (UIImage *)blur;



@end
//

//  UIImage+Blur.m

//  

//  Created by Luke on 13-9-3.

//  Copyright (c) 2013年 LukeCheng. All rights reserved.

//



#import "UIImage+Blur.h"



@implementation UIImage (Blur)



- (UIImage *)blur:(CGFloat)radius

{

    CIContext *context = [CIContext contextWithOptions:nil];

    CIImage *inputImage = [[CIImage alloc] initWithImage:self];

    // create gaussian blur filter

    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];

    [filter setValue:inputImage forKey:kCIInputImageKey];

    [filter setValue:[NSNumber numberWithFloat:radius] forKey:@"inputRadius"];

    // blur image

    CIImage *result = [filter valueForKey:kCIOutputImageKey];

    CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];

    UIImage *image = [UIImage imageWithCGImage:cgImage];

    CGImageRelease(cgImage);

    

    return image;

}



- (UIImage *)blur

{

    return [self blur:10.0f];

}



@end

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(context)