[翻译] 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上背景颜色。

 

Result Image looks like this :

结果如下所示:

 

 

附录:

“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

 

 

目录
相关文章
|
存储 自然语言处理 前端开发
从零写一个Recoil(翻译)
Rewriting Recoil from scratchrecoil是facebook编写的一个库,它之所以诞生是因为人体工程学、context的性能问题和useState。这是一个非常聪明的库,几乎每个人都会找到它的用途——如果你想了解更多,请查看这段解释视频。刚开始我被图论和recoil惊到了,但渐渐的理解后,感觉也没那么特别了。也许我也可以实现一个类似的东西。我自己实现的版本和recoil
195 0
从零写一个Recoil(翻译)
|
存储 iOS开发 Perl
|
iOS开发 编译器 Go
|
数据可视化 Perl
|
缓存 API iOS开发