Browse Source

add filter

Marino Faggiana 7 years ago
parent
commit
d5ef5859a4
2 changed files with 19 additions and 0 deletions
  1. 2 0
      iOSClient/Utility/CCGraphics.h
  2. 17 0
      iOSClient/Utility/CCGraphics.m

+ 2 - 0
iOSClient/Utility/CCGraphics.h

@@ -43,6 +43,8 @@
 + (UIColor *)colorFromHexString:(NSString *)hexString;
 + (UIImage *)changeThemingColorImage:(UIImage *)image color:(UIColor *)color;
 
++ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur;
+
 @end
 
 @interface CCAvatar : UIImageView

+ 17 - 0
iOSClient/Utility/CCGraphics.m

@@ -310,5 +310,22 @@
     return self;
 }
 
+// ------------------------------------------------------------------------------------------------------
+// MARK: Blur Image
+// ------------------------------------------------------------------------------------------------------
+
++ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur
+{
+    CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];
+    
+    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:kCIInputImageKey, inputImage, @"inputRadius", @(blur), nil];
+    
+    CIImage *outputImage = filter.outputImage;
+    CIContext *context = [CIContext contextWithOptions:nil];
+    CGImageRef outImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
+    
+    return [UIImage imageWithCGImage:outImage];
+}
+
 @end