I am making a music player app and I want A gaussian blur on the album cover image so I implemented the code that follows but the image is not filling the UIImageView
:
let bgView = UIImageView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.width))
let image = CIImage(image: (currentSong?.info.albumCover)!)
let blurFilter = CIFilter(name: "CIGaussianBlur")
blurFilter?.setValue(image, forKey: "inputImage")
let resultImage = blurFilter?.value(forKey: "outputImage") as! CIImage
let blurredImage = UIImage(ciImage: resultImage)
bgView.image = blurredImage
bgView.contentMode = UIViewContentMode.scaleAspectFit
self.addSubview(bgView)
I thought that changing the content mode to scaleAspectFit
would fix that but it did not
Update:
The Code below gives me the desired image size but without the blur. is there any reason applying a blur would cause the size of the image to be different?
let bgView = UIImageView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.width))
let image = CIImage(image: (currentSong?.info.albumCover)!)
bgView.image = image
bgView.contentMode = UIViewContentMode.scaleAspectFit
self.addSubview(bgView)