使用CoreImage教程
使用CoreImage教程
CoreImage包含有很多實用的濾鏡,專業處理圖片的庫,為了能看到各種渲染效果,請使用如下圖片素材.
?
現在可以開始教程了:
// 將UIImage轉換成CIImageCIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]];// 創建濾鏡CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectMono"keysAndValues:kCIInputImageKey, ciImage, nil];[filter setDefaults];// 獲取繪制上下文CIContext *context = [CIContext contextWithOptions:nil];// 渲染并輸出CIImageCIImage *outputImage = [filter outputImage];// 創建CGImage句柄CGImageRef cgImage = [context createCGImage:outputImagefromRect:[outputImage extent]];// 獲取圖片UIImage *showImage = [UIImage imageWithCGImage:cgImage];// 釋放CGImage句柄CGImageRelease(cgImage);// 顯示圖片UIImageView *imageView = \[[UIImageView alloc] initWithImage:FIX_IMAGE(showImage)];[self.view addSubview:imageView];代碼片段
效果如下:
我們對操作進行簡易的封裝:
CIFilterEffect.h + CIFilterEffect.m
// // CIFilterEffect.m // CIFilter // // Created by YouXianMing on 14-5-9. // Copyright (c) 2014年 Y.X. All rights reserved. //#import "CIFilterEffect.h"@interface CIFilterEffect ()@property (nonatomic, strong, readwrite) UIImage *result;@end@implementation CIFilterEffect- (instancetype)initWithImage:(UIImage *)image filterName:(NSString *)name {self = [super init];if (self){// 將UIImage轉換成CIImageCIImage *ciImage = [[CIImage alloc] initWithImage:image];// 創建濾鏡CIFilter *filter = [CIFilter filterWithName:namekeysAndValues:kCIInputImageKey, ciImage, nil];[filter setDefaults];// 獲取繪制上下文CIContext *context = [CIContext contextWithOptions:nil];// 渲染并輸出CIImageCIImage *outputImage = [filter outputImage];// 創建CGImage句柄CGImageRef cgImage = [context createCGImage:outputImagefromRect:[outputImage extent]];_result = [UIImage imageWithCGImage:cgImage];// 釋放CGImage句柄CGImageRelease(cgImage);}return self; }@end
我們來開始嘗試其他的濾鏡效果,我們可以嘗試的至少有這些:
@"CILinearToSRGBToneCurve",
@"CIPhotoEffectChrome",
@"CIPhotoEffectFade",
@"CIPhotoEffectInstant",
@"CIPhotoEffectMono",
@"CIPhotoEffectNoir",
@"CIPhotoEffectProcess",
@"CIPhotoEffectTonal",
@"CIPhotoEffectTransfer",
@"CISRGBToneCurveToLinear",
@"CIVignetteEffect",
下面是所有渲染出來的圖片,與上面提供的濾鏡名字一一對應:
?
以下效果是需要進行一些配置才能達到的效果,這個就不開源了,你懂得:).
?
?
福利:
Core Image Filter Reference
https://developer.apple.com/library/ios/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html
CICategoryBlur
- CIBoxBlur
- CIDiscBlur
- CIGaussianBlur
- CIMedianFilter
- CIMotionBlur
- CINoiseReduction
- CIZoomBlur
CICategoryColorAdjustment
- CIColorClamp
- CIColorControls
- CIColorMatrix
- CIColorPolynomial
- CIExposureAdjust
- CIGammaAdjust
- CIHueAdjust
- CILinearToSRGBToneCurve
- CISRGBToneCurveToLinear
- CITemperatureAndTint
- CIToneCurve
- CIVibrance
- CIWhitePointAdjust
CICategoryColorEffect(我們剛剛用到的一些效果在這里哦)
- CIColorCrossPolynomial
- CIColorCube
- CIColorCubeWithColorSpace
- CIColorInvert
- CIColorMap
- CIColorMonochrome
- CIColorPosterize
- CIFalseColor
- CIMaskToAlpha
- CIMaximumComponent
- CIMinimumComponent
- CIPhotoEffectChrome
- CIPhotoEffectFade
- CIPhotoEffectInstant
- CIPhotoEffectMono
- CIPhotoEffectNoir
- CIPhotoEffectProcess
- CIPhotoEffectTonal
- CIPhotoEffectTransfer
- CISepiaTone
- CIVignette
- CIVignetteEffect
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
- CIDroste
- CIDisplacementDistortion
- CIGlassDistortion
- CIGlassLozenge
- CIHoleDistortion
- CILightTunnel
- CIPinchDistortion
- CIStretchCrop
- CITorusLensDistortion
- CITwirlDistortion
- CIVortexDistortion
CICategoryGenerator
- CICheckerboardGenerator
- CIConstantColorGenerator
- CILenticularHaloGenerator
- CIQRCodeGenerator
- CIRandomGenerator
- CIStarShineGenerator
- CIStripesGenerator
- CISunbeamsGenerator
CICategoryGeometryAdjustment
- CIAffineTransform
- CICrop
- CILanczosScaleTransform
- CIPerspectiveTransform
- CIPerspectiveTransformWithExtent
- CIStraightenFilter
CICategoryGradient
- CIGaussianGradient
- CILinearGradient
- CIRadialGradient
- CISmoothLinearGradient
CICategoryHalftoneEffect
- CICircularScreen
- CICMYKHalftone
- CIDotScreen
- CIHatchedScreen
- CILineScreen
CICategoryReduction
- CIAreaAverage
- CIAreaHistogram
- CIRowAverage
- CIColumnAverage
- CIHistogramDisplayFilter
- CIAreaMaximum
- CIAreaMinimum
- CIAreaMaximumAlpha
- CIAreaMinimumAlpha
CICategorySharpen
- CISharpenLuminance
- CIUnsharpMask
CICategoryStylize
- CIBlendWithAlphaMask
- CIBlendWithMask
- CIBloom
- CIComicEffect
- CIConvolution3X3
- CIConvolution5X5
- CIConvolution7X7
- CIConvolution9Horizontal
- CIConvolution9Vertical
- CICrystallize
- CIDepthOfField
- 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
- CITriangleKaleidoscope
- CITriangleTile
- CITwelvefoldReflectedTile
CICategoryTransition
- CIBarsSwipeTransition
- CICopyMachineTransition
- CIDisintegrateWithMaskTransition
- CIDissolveTransition
- CIFlashTransition
- CIModTransition
- CIPageCurlTransition
- CIPageCurlWithShadowTransition
- CIRippleTransition
- CISwipeTransition
?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的使用CoreImage教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Can’t Activate Repor
- 下一篇: 快递100推送服务