日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用CoreImage教程

發布時間:2025/3/8 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用CoreImage教程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用CoreImage教程

CoreImage包含有很多實用的濾鏡,專業處理圖片的庫,為了能看到各種渲染效果,請使用如下圖片素材.

?

現在可以開始教程了:


#define FIX_IMAGE(image) fixImageWidth(image, 320.f)// 固定圖片的寬度 UIImage * fixImageWidth(UIImage *image, CGFloat width) {float newHeight = image.size.height * (width / image.size.width);CGSize size = CGSizeMake(width, newHeight);UIGraphicsBeginImageContextWithOptions(size, NO, 0);CGContextRef context = UIGraphicsGetCurrentContext();CGContextTranslateCTM(context, 0.0, size.height);CGContextScaleCTM(context, 1.0, -1.0);CGContextSetBlendMode(context, kCGBlendModeCopy);CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height),image.CGImage);UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return imageOut; }代碼片段

// 將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.h // CIFilter // // Created by YouXianMing on 14-5-9. // Copyright (c) 2014年 Y.X. All rights reserved. //#import <Foundation/Foundation.h>@interface CIFilterEffect : NSObject@property (nonatomic, strong, readonly) UIImage *result;- (instancetype)initWithImage:(UIImage *)image filterName:(NSString *)name;@end

// // 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教程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。