可能错过的精彩
高斯模糊
- 全局模糊
texelSpacingMultiplier是模糊的强度,数值越大,模糊效果越明显
blurRadiusInPixels是像素范围,用于计算平均值。
+ (UIImage *)applyGaussianBlur:(UIImage *)image
{
GPUImageGaussianBlurFilter *filter = [[GPUImageGaussianBlurFilter alloc] init];
filter.texelSpacingMultiplier = 5.0;
filter.blurRadiusInPixels = 5.0;
[filter forceProcessingAtSize:image.size];
GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];
[pic addTarget:filter];
[pic processImage];
[filter useNextFrameForImageCapture];
return [filter imageFromCurrentFramebuffer];
}
- 局部模糊
GPUImageGaussianSelectiveBlurFilter可以部分模糊,也就是选区外模糊
excludeCircleRadius用来调整模糊区域
+ (UIImage *)applyGaussianSelectiveBlur:(UIImage *)image{
GPUImageGaussianSelectiveBlurFilter *filter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
// filter.texelSpacingMultiplier = 5.0;
filter.excludeCircleRadius = 120 / 320.0;
[filter forceProcessingAtSize:image.size];
GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];
[pic addTarget:filter];
[pic processImage];
[filter useNextFrameForImageCapture];
return [filter imageFromCurrentFramebuffer];
}
补充系统 iOS8 后自带模糊
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
effectView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self.view addSubview:effectView];