GPUImage 是基於 GPU 處理圖像的一個開源庫, 提供了各類圖像處理濾鏡,例如調 亮度/飽和度/曝光度/白平衡/銳化等濾鏡.html
而且支持照相機/攝像機 的實時濾鏡.ios
GPUImage採用鏈式方式來處理畫面,經過addTarget:方法爲鏈條添加每一個環節的對象,處理完一個target,就會把上一個環節處理好的圖像數據傳遞下一個target去處理,稱爲GPUImage處理鏈.git
https://github.com/BradLarson/GPUImagegithub
圖片濾鏡ide
//調整圖像的對比度 - (void)changeContrast{ //對比度 // GPUImageContrastFilter *filter = [[GPUImageContrastFilter alloc]init]; // filter.contrast = self.slider.value; //飽和度 // GPUImageSaturationFilter *filter = [[GPUImageSaturationFilter alloc]init]; // filter.saturation = self.slider.value; //曝光度 // GPUImageExposureFilter *filter = [[GPUImageExposureFilter alloc] init]; // filter.exposure = self.slider.value; //色溫(白平衡) GPUImageWhiteBalanceFilter *filter = [[GPUImageWhiteBalanceFilter alloc] init]; filter.temperature = self.slider.value; filter.tint = 0.0; //設置要渲染的區域 [filter forceProcessingAtSize:_image.size]; //獲取 GPU 圖片 GPUImagePicture *pic = [[GPUImagePicture alloc]initWithImage:_image]; //添加濾鏡 [pic addTarget:filter]; //開始渲染 [pic processImage]; //(須要調用一下? why?) [filter useNextFrameForImageCapture]; //獲取渲染後的圖片 UIImage *newImage = [filter imageFromCurrentFramebuffer]; self.imageView.image = newImage; }
實時相機濾鏡spa
//建立相機(注意:當前vc需持有camera, 不然會提早釋放) camera = [[GPUImageVideoCamera alloc]initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:AVCaptureDevicePositionFront]; camera.outputImageOrientation = UIInterfaceOrientationPortrait; //建立最終預覽視圖 view GPUImageView *cameraView = [[GPUImageView alloc]initWithFrame:self.view.frame]; [self.view insertSubview:cameraView atIndex:0]; //建立濾鏡組合: 磨皮,美白 GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init]; //磨皮濾鏡 GPUImageBilateralFilter *bilateralFilter = [[GPUImageBilateralFilter alloc]init]; [groupFilter addTarget:bilateralFilter]; //美白濾鏡 GPUImageBrightnessFilter *brightFilter = [[GPUImageBrightnessFilter alloc]init]; [groupFilter addTarget:brightFilter]; //設置濾鏡組鏈 [bilateralFilter addTarget:brightFilter]; [groupFilter setInitialFilters:@[bilateralFilter]]; groupFilter.terminalFilter = brightFilter; //設置 GPUImage 處理鏈,從數據源->濾鏡->最終頁面效果 [camera addTarget:groupFilter]; [groupFilter addTarget:cameraView]; //相機開始捕獲 [camera startCameraCapture];
參考:.net
//濾鏡效果code
http://blog.csdn.net/gaojq_ios/article/details/46926559htm
//實時濾鏡(相機)對象
https://www.jianshu.com/p/b1d3ef7fdf7a
https://www.jianshu.com/p/2ce9b63ecfef
http://blog.csdn.net/xoxo_x/article/details/58357978
博客:(總結)
http://blog.csdn.net/xoxo_x/article/details/52695032
GPUImage 原理
http://blog.csdn.net/qq_29846663/article/details/53707482
GPUImage全部濾鏡介紹
http://www.360doc.com/content/15/0907/10/19175681_497418716.shtml