Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Blur image using objective-c and swift

    • 0
    • 4
    • 2
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.63k
    Comment on it

    Hello Reader's



    If you want to blur image in objective c and swift then copy this code in your project and just call this function. In this code , Blur effect is 50 percent .



    For Objective C :-


    -(UIImage *)convertToBlurImage:(UIImage *)image{
        CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
        [gaussianBlurFilter setDefaults];
        CIImage *inputImage = [CIImage imageWithCGImage:[image CGImage]];
        [gaussianBlurFilter setValue:inputImage forKey:kCIInputImageKey];
        [gaussianBlurFilter setValue:@50 forKey:kCIInputRadiusKey];
    
        CIImage *outputImage = [gaussianBlurFilter outputImage];
        CIContext *context   = [CIContext contextWithOptions:nil];
        CGImageRef cgimg     = [context createCGImage:outputImage fromRect:[inputImage extent]];  // note, use input image extent if you want it the same size, the output image extent is larger
        UIImage *convertedImage = [UIImage imageWithCGImage:cgimg];
        return convertedImage;
    }
    



    For Swift :-


    func convertToBlurImage(image:UIImage)->(UIImage){
            var imageToBlur = CIImage(image: image)
            var blurfilter = CIFilter(name: "CIGaussianBlur")
            blurfilter.setValue("5", forKey:kCIInputRadiusKey)
            blurfilter.setValue(imageToBlur, forKey: "inputImage")
            var resultImage = blurfilter.valueForKey("outputImage") as CIImage
            var blurredImage = UIImage(CIImage: resultImage)
            return blurredImage!
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: