iosswiftcore-imagecifilterciimage

How to Remove Black Shadow Rectangle from Image when Applying Blur Filter in iOS?


I want to remove a BLACK shadow border around Image when applying a Blur filter.

Please review below-attached screenshot. Blur function work correctly but want to remove a black shadow. I only want to do blur an Image. I don't want to apply any color effect with blur. Please let us know when should I missed...

Here I Have uploaded Image due to the low points:

https://drive.google.com/open?id=1KtVgqRXOmIEQXh9IMyWNAlariL0hcJBN https://drive.google.com/open?id=1l2eLq7VwFPb3-SfIokW0Ijhk2jqUvjlU

Here is my function to Apply Blur effects on particular Image:

Parameter :

doBlurImage - Main Image want to Blur it

imageBlurValue - Blur value from 0 to 50 Float

func makeBlurImage(doBlurImage : UIImage, imageBlurValue :  CGFloat) -> UIImage {

        let beginImage = CIImage(image: doBlurImage)

        let currentFilter = CIFilter(name: "CIGaussianBlur")
        currentFilter!.setValue(beginImage, forKey: kCIInputImageKey)
        currentFilter!.setValue(imageBlurValue, forKey: kCIInputRadiusKey)

        let cropFilter = CIFilter(name: "CICrop")
        cropFilter!.setValue(currentFilter!.outputImage, forKey: kCIInputImageKey)
        cropFilter!.setValue(CIVector(cgRect: beginImage!.extent), forKey: "inputRectangle")

        let output = cropFilter!.outputImage


        return UIImage(ciImage: output!)
}

Solution

  • These are possible options to generate a Blur effect in ios:

    1. CIGaussianBlur will generate a Blur effect based on a background color of Image.
    2. UIVisualEffectView will generate a Blur effect based on a Style of UIVisualEffectView. Blur effect in UIVisualEffectView are .extraLight, .light, .dark, .extraDark, regular, and prominent.
    3. Suggested Option - GPUIMage - You can archive best blur effect using GPUImage Processing Library.

    Blur effect using GPUImage:

                var resultImage = UIImage()
                let gaussianBlur = GaussianBlur()
                gaussianBlur.blurRadiusInPixels = Float(ImageBlurValue)
                let pictureInput = PictureInput(image: YourImage)
                let pictureOutput = PictureOutput()
                pictureOutput.imageAvailableCallback = {image in
                    print("Process completed")
    
                    resultImage = image
                }
                pictureInput --> gaussianBlur --> pictureOutput
                pictureInput.processImage(synchronously:true)
    
                pictureInput.removeAllTargets()
                return resultImage
    

    Happy Coding!...:)