iOS中滤镜的使用(二)滤镜组合

原创 2015年07月09日 11:18:49

iOS中滤镜的使用(二)

滤镜组合



首先 要加载图片并转化为CIImage

CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0160"]];

其次,创建filter滤镜

 CIFilter *filterOne = [CIFilter filterWithName:@"CIPixellate"];//马赛克滤镜

    NSLog(@"%@",filterOne.attributes);
    [filterOne setValue:ciImage  forKey:kCIInputImageKey];
    [filterOne setDefaults];
    CIImage *outImage = [filterOne valueForKey:kCIOutputImageKey];

    CIFilter *filterTwo = [CIFilter filterWithName:@"CIHueAdjust"];//饱和度滤镜

    [filterTwo setValue:outImage  forKey:kCIInputImageKey];
    [filterTwo setDefaults];

    NSLog(@"%@",filterTwo.attributes);//打印可修改的属性
    [filterTwo setValue:@(3.14) forKey:kCIInputAngleKey];//位置不能改变

    CIImage *outImageTwo = [filterTwo valueForKey:kCIOutputImageKey];

然后,用CIContext将滤镜中的图片渲染出来,原因,导出图片过过程中用到CGImageRef。

CIContext *context = [CIContext contextWithOptions:nil];

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

最后,导出图片,注意内存的释放

 UIImage *showImage = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

剩下的工作就是加载马赛克图片了

 UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 600, 400)];
imageView.image = showImage;
imageView.center = self.view.center;
[self.view addSubview:imageView];

而马赛克Filter的属性有如下:
马赛克属性

饱和度Filter的属性如下:
饱和度属性

总的代码如下:

 //0:导入图片

    CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0160"]];
    //1:创建filter组合滤镜
      CIFilter *filterOne = [CIFilter filterWithName:@"CIPixellate"];//马赛克滤镜

    NSLog(@"%@",filterOne.attributes);
    [filterOne setValue:ciImage  forKey:kCIInputImageKey];
    [filterOne setDefaults];
    CIImage *outImage = [filterOne valueForKey:kCIOutputImageKey];

    CIFilter *filterTwo = [CIFilter filterWithName:@"CIHueAdjust"];//饱和度滤镜

    [filterTwo setValue:outImage  forKey:kCIInputImageKey];
    [filterTwo setDefaults];

    NSLog(@"%@",filterTwo.attributes);//打印可修改的属性
    [filterTwo setValue:@(3.14) forKey:kCIInputAngleKey];//位置不能改变

    CIImage *outImageTwo = [filterTwo valueForKey:kCIOutputImageKey];


    //2:用CIContext将滤镜中的图片渲染出来

    CIContext *context = [CIContext contextWithOptions:nil];

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

    //3:导出图片

    UIImage *showImage = [UIImage imageWithCGImage:cgImage];

    CGImageRelease(cgImage);

    //4:加载出来

    UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 600, 400)];
    imageView.image = showImage;
    imageView.center = self.view.center;
    [self.view addSubview:imageView];

滤镜组合的种类有如下:
//Iphone中目前可用的
CIAdditionCompositing //影像合成

CIAffineTransform           //仿射变换

CICheckerboardGenerator       //棋盘发生器

CIColorBlendMode              //CIColor混合模式

CIColorBurnBlendMode          //CIColor燃烧混合模式

CIColorControls 

CIColorCube                   //立方体

CIColorDodgeBlendMode         //CIColor避免混合模式

CIColorInvert                 //CIColor反相

CIColorMatrix                 //CIColor矩阵

CIColorMonochrome             //黑白照

CIConstantColorGenerator      //恒定颜色发生器

CICrop                        //裁剪

CIDarkenBlendMode             //亮度混合模式

CIDifferenceBlendMode         //差分混合模式

CIExclusionBlendMode          //互斥混合模式

CIExposureAdjust              //曝光调节

CIFalseColor                  //伪造颜色

CIGammaAdjust                 //灰度系数调节

CIGaussianGradient            //高斯梯度

CIHardLightBlendMode          //强光混合模式

CIHighlightShadowAdjust       //高亮阴影调节

CIHueAdjust                   //饱和度调节

CIHueBlendMode                //饱和度混合模式

CILightenBlendMode            

CILinearGradient              //线性梯度

CILuminosityBlendMode         //亮度混合模式

CIMaximumCompositing          //最大合成

CIMinimumCompositing          //最小合成

CIMultiplyBlendMode           //多层混合模式

CIMultiplyCompositing         //多层合成

CIOverlayBlendMode            //覆盖叠加混合模式

CIRadialGradient              //半径梯度

CISaturationBlendMode         //饱和度混合模式

CIScreenBlendMode             //全屏混合模式

CISepiaTone                   //棕黑色调

CISoftLightBlendMode          //弱光混合模式

CISourceAtopCompositing       

CISourceInCompositing 

CISourceOutCompositing 

CISourceOverCompositing 

CIStraightenFilter            //拉直过滤器

CIStripesGenerator            //条纹发生器

CITemperatureAndTint          //色温

CIToneCurve                   //色调曲线

CIVibrance                    //振动

CIVignette                    //印花

CIWhitePointAdjust            //白平衡调节

官方文档中列表:

CICategoryBlur
CIBoxBlur
CIDiscBlur
CIGaussianBlur
CIMedianFilter
CIMotionBlur
CINoiseReduction
CIZoomBlur

CICategoryColorAdjustment
CIColorControls
CIColorMatrix
CIExposureAdjust
CIGammaAdjust
CIHueAdjust
CITemperatureAndTint
CIToneCurve
CIVibrance
CIWhitePointAdjust

CICategoryColorEffect
CIColorCube
CIColorInvert
CIColorMap
CIColorMonochrome
CIColorPosterize
CIFalseColor
CIMaskToAlpha
CIMaximumComponent
CIMinimumComponent
CISepiaTone

CICategoryCompositeOperation
CIAdditionCompositing
CIColorBlendMode
CIColorBurnBlendMode
CIColorDodgeBlendMode
CIDarkenBlendMode
CIDifferenceBlendMode
CIExclusionBlendMode
CIHardLightBlendMode
CIHueBlendMode
CILightenBlendMode
CILuminosityBlendMode
CIMaximumCompositing
CIMinimumCompositing
CIMultiplyBlendMode
CIMultiplyCompositing
CIOverlayBlendMode
CISaturationBlendMode
CIScreenBlendMode
CISoftLightBlendMode
CISourceAtopCompositing
CISourceInCompositing
CISourceOutCompositing
CISourceOverCompositing

CICategoryDistortionEffect
CIBumpDistortion
CIBumpDistortionLinear
CICircleSplashDistortion
CICircularWrap
CIDisplacementDistortion
CIGlassDistortion
CIGlassLozenge
CIHoleDistortion
CIPinchDistortion
CITorusLensDistortion
CITwirlDistortion
CIVortexDistortion

CICategoryGenerator
CICheckerboardGenerator
CIConstantColorGenerator
CILenticularHaloGenerator
CIRandomGenerator
CIStarShineGenerator
CIStripesGenerator
CISunbeamsGenerator

CICategoryGeometryAdjustment
CIAffineTransform
CICrop
CILanczosScaleTransform
CIPerspectiveTransform
CIStraightenFilter

CICategoryGradient
CIGaussianGradient
CILinearGradient
CIRadialGradient

CICategoryHalftoneEffect
CICircularScreen
CICMYKHalftone
CIDotScreen
CIHatchedScreen
CILineScreen

CICategoryReduction
CIAreaAverage
CIAreaHistogram
CIRowAverage
CIColumnAverage
CIAreaMaximum
CIAreaMinimum
CIAreaMaximumAlpha
CIAreaMinimumAlpha

CICategorySharpen
CISharpenLuminance
CIUnsharpMask

CICategoryStylize
CIBlendWithMask
CIBloom
CIComicEffect
CICrystallize
CIEdges
CIEdgeWork
CIGloom
CIHeightFieldFromMask
CIHexagonalPixellate
CIHighlightShadowAdjust
CILineOverlay
CIPixellate
CIPointillize
CIShadedMaterial
CISpotColor
CISpotLight

CICategoryTileEffect
CIAffineClamp
CIAffineTile
CIEightfoldReflectedTile
CIFourfoldReflectedTile
CIFourfoldRotatedTile
CIFourfoldTranslatedTile
CIGlideReflectedTile
CIKaleidoscope
CIOpTile
CIParallelogramTile
CIPerspectiveTile
CISixfoldReflectedTile
CISixfoldRotatedTile
CITriangleTile
CITwelvefoldReflectedTile

CICategoryTransition
CIBarsSwipeTransition
CICopyMachineTransition
CIDisintegrateWithMaskTransition
CIDissolveTransition
CIFlashTransition
CIModTransition
CIPageCurlTransition
CIRippleTransition
CISwipeTransition

相关文章推荐

iOS 开发 二维码生成大全(黑白/彩色二维码和带图片的二维码)详解

前言扫描二维码使用的是coreImage框架,属于UIKit框架中的体系,多以使用时不用导入coreImage框架开始之前,让我们谈谈Core Image框架中最重要的几个类: CIContext. ...

opengles2——3.着色器和编程

【着色器和项目】   使用着色器渲染有两个基本的对象类型你需要去创建:着色器对象和项目对象。着色器对象是包含单个着色器的物体。源码输入着色器对象, 着色器对象被编辑为目标格式(.obj文件)。完成后着...

基于OpenGL的滤镜架构搭建(IOS)

最近  为别的项目组写了一个基于openGL的实时滤镜架构,在此把遇到的问题和所得记录下。...

GPUImage 简单使用(二)组合滤镜使用

这里组合滤镜我使用的是GPUImageFilterPipeline这个类  一、步骤: 1、创建图片处理类 GPUImagePicture 把图片传进去stillImage GPUImage...

iOS GPUImage之GPUImageFilterGroup组合滤镜(5)

【提醒】 添加滤镜的顺序不同,效果也不同!示例:使用GPUImageFilterGroup为GPUImagePicture添加组合滤镜代码: // // ViewController.m...

iOS GPUImage之GPUImageFilterPipeline组合滤镜(4)

实现滤镜的组合(又称混合滤镜)示例:为静态图片添加组合滤镜 注意:组合滤镜的添加顺序不同,处理结果也不同!代码: // // ViewController.m // GPUImageTest //...

ios滤镜使用

  • 2016年06月27日 19:42
  • 599KB
  • 下载

iOS 使用GPUImage为本地视频添加滤镜

iOS视频滤镜添加,下面介绍使用GPUImage给本地视频添加滤镜

iOS中滤镜的使用(三)OpenGLES渲染

iOS中滤镜的使用(三)OpenGLES渲染首先,Open Graphics Library(OpenGL)用于二维和三维的可视化。而OpenGL for Embedded Systems(OpenG...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:iOS中滤镜的使用(二)滤镜组合
举报原因:
原因补充:

(最多只允许输入30个字)