关闭

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

标签: iosfilter滤镜图片
903人阅读 评论(0) 收藏 举报
分类:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:25844次
    • 积分:494
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:14篇
    • 译文:0篇
    • 评论:0条