您好,登錄后才能下訂單哦!
GPUImage 是一個(gè)開源的圖像處理庫,提供了非常多的濾鏡效果來加工圖片。GPUImage 并不像一般的第三方庫可以直接拖入到工程中使用,而是需要先在本地編譯,然后將編譯后的文件拖入到工程中使用。配置步驟如下:
(1):首先下載GPUImage https://github.com/BradLarson/GPUImage
(2):解壓后,在framework 目錄下,打開 GPUImage.xcodeproj 工程
(3):
把Headers文件夾下 Project中的頭文件,全部拖到 Public文件夾下面
(4):運(yùn)行該工程
(5)點(diǎn)擊Products下的 libGPUImage.a,右鍵, show in finder
(6)把該目錄下的libGpuImage.a 和 User文件夾拖到我們的工程下面
(7)然后就可以使用 GPUImage了。一個(gè)示例代碼:
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 4 UIImage *inputImage = [UIImage p_w_picpathNamed:@"zzy"]; 5 //創(chuàng)建一個(gè)亮度的濾鏡 6 // GPUImageBrightnessFilter *passthroughFilter = [[GPUImageBrightnessFilter alloc] init]; 7 // passthroughFilter.brightness = -0.5f; 8 // //設(shè)置要渲染的區(qū)域 9 // [passthroughFilter forceProcessingAtSize:inputImage.size];10 // [passthroughFilter useNextFrameForImageCapture];11 // //獲取數(shù)據(jù)源12 // GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:inputImage];13 // //添加上濾鏡14 // [stillImageSource addTarget:passthroughFilter];15 // //開始渲染16 // [stillImageSource processImage];17 // //獲取渲染后的圖片18 // UIImage *newImage = [passthroughFilter p_w_picpathFromCurrentFramebuffer];19 // //加載出來20 // UIImageView *p_w_picpathView = [[UIImageView alloc] initWithImage:newImage];21 // p_w_picpathView.frame = CGRectMake(0,0,inputImage.size.width ,inputImage.size.height);22 // [self.view addSubview:p_w_picpathView];23 24 25 //GPUImageStretchDistortionFilter *disFilter =[[GPUImageStretchDistortionFilter alloc] init];26 //GPUImageBulgeDistortionFilter *disFilter = [[GPUImageBulgeDistortionFilter alloc] init];27 //GPUImagePinchDistortionFilter *disFilter = [[GPUImagePinchDistortionFilter alloc] init];28 //GPUImageGlassSphereFilter *disFilter = [[GPUImageGlassSphereFilter alloc] init];29 //GPUImageSphereRefractionFilter *disFilter = [[GPUImageSphereRefractionFilter alloc] init];30 //GPUImageToonFilter *disFilter = [[GPUImageToonFilter alloc] init];31 GPUImageVignetteFilter *disFilter = [[GPUImageVignetteFilter alloc] init];32 //設(shè)置要渲染的區(qū)域33 [disFilter forceProcessingAtSize:inputImage.size];34 [disFilter useNextFrameForImageCapture];35 //獲取數(shù)據(jù)源36 GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:inputImage];37 //添加上濾鏡38 [stillImageSource addTarget:disFilter];39 //開始渲染40 [stillImageSource processImage];41 //獲取渲染后的圖片42 UIImage *newImage = [disFilter p_w_picpathFromCurrentFramebuffer];43 //加載出來44 UIImageView *p_w_picpathView = [[UIImageView alloc] initWithImage:newImage];45 p_w_picpathView.frame = CGRectMake(50,50,inputImage.size.width ,inputImage.size.height);46 [self.view addSubview:p_w_picpathView];47 }
GPUImage提供的過濾器很多,每個(gè)頭文件就是一個(gè)過濾器,這里貼一個(gè)過濾器的簡介:
1 #import "GLProgram.h" 2 3 // Base classes 4 #import "GPUImageOpenGLESContext.h" 5 #import "GPUImageOutput.h" 6 #import "GPUImageView.h" 7 #import "GPUImageVideoCamera.h" 8 #import "GPUImageStillCamera.h" 9 #import "GPUImageMovie.h" 10 #import "GPUImagePicture.h" 11 #import "GPUImageRawDataInput.h" 12 #import "GPUImageRawDataOutput.h" 13 #import "GPUImageMovieWriter.h" 14 #import "GPUImageFilterPipeline.h" 15 #import "GPUImageTextureOutput.h" 16 #import "GPUImageFilterGroup.h" 17 #import "GPUImageTextureInput.h" 18 #import "GPUImageUIElement.h" 19 #import "GPUImageBuffer.h" 20 21 // Filters 22 #import "GPUImageFilter.h" 23 #import "GPUImageTwoInputFilter.h" 24 25 26 #pragma mark - 調(diào)整顏色 Handle Color 27 28 #import "GPUImageBrightnessFilter.h" //亮度 29 #import "GPUImageExposureFilter.h" //曝光 30 #import "GPUImageContrastFilter.h" //對(duì)比度 31 #import "GPUImageSaturationFilter.h" //飽和度 32 #import "GPUImageGammaFilter.h" //伽馬線 33 #import "GPUImageColorInvertFilter.h" //反色 34 #import "GPUImageSepiaFilter.h" //褐色(懷舊) 35 #import "GPUImageLevelsFilter.h" //色階 36 #import "GPUImageGrayscaleFilter.h" //灰度 37 #import "GPUImageHistogramFilter.h" //色彩直方圖,顯示在圖片上 38 #import "GPUImageHistogramGenerator.h" //色彩直方圖 39 #import "GPUImageRGBFilter.h" //RGB 40 #import "GPUImageToneCurveFilter.h" //色調(diào)曲線 41 #import "GPUImageMonochromeFilter.h" //單色 42 #import "GPUImageOpacityFilter.h" //不透明度 43 #import "GPUImageHighlightShadowFilter.h" //提亮陰影 44 #import "GPUImageFalseColorFilter.h" //色彩替換(替換亮部和暗部色彩) 45 #import "GPUImageHueFilter.h" //色度 46 #import "GPUImageChromaKeyFilter.h" //色度鍵 47 #import "GPUImageWhiteBalanceFilter.h" //白平橫 48 #import "GPUImageAverageColor.h" //像素平均色值 49 #import "GPUImageSolidColorGenerator.h" //純色 50 #import "GPUImageLuminosity.h" //亮度平均 51 #import "GPUImageAverageLuminanceThresholdFilter.h" //像素色值亮度平均,圖像黑白(有類似漫畫效果) 52 53 #import "GPUImageLookupFilter.h" //lookup 色彩調(diào)整 54 #import "GPUImageAmatorkaFilter.h" //Amatorka lookup 55 #import "GPUImageMissEtikateFilter.h" //MissEtikate lookup 56 #import "GPUImageSoftEleganceFilter.h" //SoftElegance lookup 57 58 59 60 61 #pragma mark - 圖像處理 Handle Image 62 63 #import "GPUImageCrosshairGenerator.h" //十字 64 #import "GPUImageLineGenerator.h" //線條 65 66 #import "GPUImageTransformFilter.h" //形狀變化 67 #import "GPUImageCropFilter.h" //剪裁 68 #import "GPUImageSharpenFilter.h" //銳化 69 #import "GPUImageUnsharpMaskFilter.h" //反遮罩銳化 70 71 #import "GPUImageFastBlurFilter.h" //模糊 72 #import "GPUImageGaussianBlurFilter.h" //高斯模糊 73 #import "GPUImageGaussianSelectiveBlurFilter.h" //高斯模糊,選擇部分清晰 74 #import "GPUImageBoxBlurFilter.h" //盒狀模糊 75 #import "GPUImageTiltShiftFilter.h" //條紋模糊,中間清晰,上下兩端模糊 76 #import "GPUImageMedianFilter.h" //中間值,有種稍微模糊邊緣的效果 77 #import "GPUImageBilateralFilter.h" //雙邊模糊 78 #import "GPUImageErosionFilter.h" //侵蝕邊緣模糊,變黑白 79 #import "GPUImageRGBErosionFilter.h" //RGB侵蝕邊緣模糊,有色彩 80 #import "GPUImageDilationFilter.h" //擴(kuò)展邊緣模糊,變黑白 81 #import "GPUImageRGBDilationFilter.h" //RGB擴(kuò)展邊緣模糊,有色彩 82 #import "GPUImageOpeningFilter.h" //黑白色調(diào)模糊 83 #import "GPUImageRGBOpeningFilter.h" //彩色模糊 84 #import "GPUImageClosingFilter.h" //黑白色調(diào)模糊,暗色會(huì)被提亮 85 #import "GPUImageRGBClosingFilter.h" //彩色模糊,暗色會(huì)被提亮 86 #import "GPUImageLanczosResamplingFilter.h" //Lanczos重取樣,模糊效果 87 #import "GPUImageNonMaximumSuppressionFilter.h" //非最大抑制,只顯示亮度最高的像素,其他為黑 88 #import "GPUImageThresholdedNonMaximumSuppressionFilter.h" //與上相比,像素丟失更多 89 90 #import "GPUImageSobelEdgeDetectionFilter.h" //Sobel邊緣檢測(cè)算法(白邊,黑內(nèi)容,有點(diǎn)漫畫的反色效果) 91 #import "GPUImageCannyEdgeDetectionFilter.h" //Canny邊緣檢測(cè)算法(比上更強(qiáng)烈的黑白對(duì)比度) 92 #import "GPUImageThresholdEdgeDetectionFilter.h" //閾值邊緣檢測(cè)(效果與上差別不大) 93 #import "GPUImagePrewittEdgeDetectionFilter.h" //普瑞維特(Prewitt)邊緣檢測(cè)(效果與Sobel差不多,貌似更平滑) 94 #import "GPUImageXYDerivativeFilter.h" //XYDerivative邊緣檢測(cè),畫面以藍(lán)色為主,綠色為邊緣,帶彩色 95 #import "GPUImageHarrisCornerDetectionFilter.h" //Harris角點(diǎn)檢測(cè),會(huì)有綠色小十字顯示在圖片角點(diǎn)處 96 #import "GPUImageNobleCornerDetectionFilter.h" //Noble角點(diǎn)檢測(cè),檢測(cè)點(diǎn)更多 97 #import "GPUImageShiTomasiFeatureDetectionFilter.h" //ShiTomasi角點(diǎn)檢測(cè),與上差別不大 98 #import "GPUImageMotionDetector.h" //動(dòng)作檢測(cè) 99 #import "GPUImageHoughTransformLineDetector.h" //線條檢測(cè)100 #import "GPUImageParallelCoordinateLineTransformFilter.h" //平行線檢測(cè)101 102 #import "GPUImageLocalBinaryPatternFilter.h" //圖像黑白化,并有大量噪點(diǎn)103 104 #import "GPUImageLowPassFilter.h" //用于圖像加亮105 #import "GPUImageHighPassFilter.h" //圖像低于某值時(shí)顯示為黑106 107 108 #pragma mark - 視覺效果 Visual Effect109 110 #import "GPUImageSketchFilter.h" //素描111 #import "GPUImageThresholdSketchFilter.h" //閥值素描,形成有噪點(diǎn)的素描112 #import "GPUImageToonFilter.h" //卡通效果(黑色粗線描邊)113 #import "GPUImageSmoothToonFilter.h" //相比上面的效果更細(xì)膩,上面是粗曠的畫風(fēng)114 #import "GPUImageKuwaharaFilter.h" //桑原(Kuwahara)濾波,水粉畫的模糊效果;處理時(shí)間比較長,慎用115 116 #import "GPUImageMosaicFilter.h" //黑白馬賽克117 #import "GPUImagePixellateFilter.h" //像素化118 #import "GPUImagePolarPixellateFilter.h" //同心圓像素化119 #import "GPUImageCrosshatchFilter.h" //交叉線陰影,形成黑白網(wǎng)狀畫面120 #import "GPUImageColorPackingFilter.h" //色彩丟失,模糊(類似監(jiān)控?cái)z像效果)121 122 #import "GPUImageVignetteFilter.h" //暈影,形成黑色圓形邊緣,突出中間圖像的效果123 #import "GPUImageSwirlFilter.h" //漩渦,中間形成卷曲的畫面124 #import "GPUImageBulgeDistortionFilter.h" //凸起失真,魚眼效果125 #import "GPUImagePinchDistortionFilter.h" //收縮失真,凹面鏡126 #import "GPUImageStretchDistortionFilter.h" //伸展失真,哈哈鏡127 #import "GPUImageGlassSphereFilter.h" //水晶球效果128 #import "GPUImageSphereRefractionFilter.h" //球形折射,圖形倒立129 130 #import "GPUImagePosterizeFilter.h" //色調(diào)分離,形成噪點(diǎn)效果131 #import "GPUImageCGAColorspaceFilter.h" //CGA色彩濾鏡,形成黑、淺藍(lán)、紫色塊的畫面132 #import "GPUImagePerlinNoiseFilter.h" //柏林噪點(diǎn),花邊噪點(diǎn)133 #import "GPUImage3x3ConvolutionFilter.h" //3x3卷積,高亮大色塊變黑,加亮邊緣、線條等134 #import "GPUImageEmbossFilter.h" //浮雕效果,帶有點(diǎn)3d的感覺135 #import "GPUImagePolkaDotFilter.h" //像素圓點(diǎn)花樣136 #import "GPUImageHalftoneFilter.h" //點(diǎn)染,圖像黑白化,由黑點(diǎn)構(gòu)成原圖的大致圖形137 138 139 #pragma mark - 混合模式 Blend140 141 #import "GPUImageMultiplyBlendFilter.h" //通常用于創(chuàng)建陰影和深度效果142 #import "GPUImageNormalBlendFilter.h" //正常143 #import "GPUImageAlphaBlendFilter.h" //透明混合,通常用于在背景上應(yīng)用前景的透明度144 #import "GPUImageDissolveBlendFilter.h" //溶解145 #import "GPUImageOverlayBlendFilter.h" //疊加,通常用于創(chuàng)建陰影效果146 #import "GPUImageDarkenBlendFilter.h" //加深混合,通常用于重疊類型147 #import "GPUImageLightenBlendFilter.h" //減淡混合,通常用于重疊類型148 #import "GPUImageSourceOverBlendFilter.h" //源混合149 #import "GPUImageColorBurnBlendFilter.h" //色彩加深混合150 #import "GPUImageColorDodgeBlendFilter.h" //色彩減淡混合151 #import "GPUImageScreenBlendFilter.h" //屏幕包裹,通常用于創(chuàng)建亮點(diǎn)和鏡頭眩光152 #import "GPUImageExclusionBlendFilter.h" //排除混合153 #import "GPUImageDifferenceBlendFilter.h" //差異混合,通常用于創(chuàng)建更多變動(dòng)的顏色154 #import "GPUImageSubtractBlendFilter.h" //差值混合,通常用于創(chuàng)建兩個(gè)圖像之間的動(dòng)畫變暗模糊效果155 #import "GPUImageHardLightBlendFilter.h" //強(qiáng)光混合,通常用于創(chuàng)建陰影效果156 #import "GPUImageSoftLightBlendFilter.h" //柔光混合157 #import "GPUImageChromaKeyBlendFilter.h" //色度鍵混合158 #import "GPUImageMaskFilter.h" //遮罩混合159 #import "GPUImageHazeFilter.h" //朦朧加暗160 #import "GPUImageLuminanceThresholdFilter.h" //亮度閾161 #import "GPUImageAdaptiveThresholdFilter.h" //自適應(yīng)閾值162 #import "GPUImageAddBlendFilter.h" //通常用于創(chuàng)建兩個(gè)圖像之間的動(dòng)畫變亮模糊效果163 #import "GPUImageDivideBlendFilter.h" //通常用于創(chuàng)建兩個(gè)圖像之間的動(dòng)畫變暗模糊效果164 165 166 #pragma mark - 尚不清楚167 #import "GPUImageJFAVoroniFilter.h"168 #import "GPUImageVoroniConsumerFilter.h"
PS:GPUImage 功能非常強(qiáng)大,可以將照片做成類似于哈哈鏡的效果,效果圖如下:
原圖:
處理后的圖:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。