我使用UIVisualEffectView来模糊我的图像视图。然后我使用此代码将其转换为图像并保存到图像库。
UIGraphicsBeginImageContextWithOptions(imageContainerView.bounds.size, true, 1)
imageContainerView.drawHierarchy(in: imageContainerView.bounds, afterScreenUpdates: true)
let newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()imageContainerView是一个包含imageview和UIVisualEffectView的视图。
在我将imageContainerView转换成图像之前,我将它的大小增加到2000x2000,这样我就会得到高质量的图像,如果我不这样做,imageContainerView中的所有图像都会变得像素化。
问题是,在将imageContainerView转换为图像后,模糊的图像几乎不会变得模糊,因为我增加了容器视图的大小。
你能为这个问题提出一个解决方案吗?我只想得到一个模糊的图像,所以如果你知道其他方法来模糊图像使用滑块(模糊代码应该工作得很快,所以UI不会冻结),请告诉我。
发布于 2018-08-28 18:36:35
我只想得到一个模糊的图像
好的,你可以实现一些模糊滤镜效果,比如这个,然后滑动到它上面。
var context = CIContext(options: nil)
func blur() {
let blurFilter = CIFilter(name: "CIGaussianBlur")
let beginImage = CIImage(image: YOURIMAGE!)
blurFilter!.setValue(beginImage, forKey: kCIInputImageKey)
blurFilter!.setValue(8, forKey: kCIInputRadiusKey)
let cropFilter = CIFilter(name: "CICrop")
cropFilter!.setValue(blurFilter!.outputImage, forKey: kCIInputImageKey)
cropFilter!.setValue(CIVector(cgRect: beginImage!.extent), forKey: "inputRectangle")
let output = cropFilter!.outputImage
let cgImg = context.createCGImage(output!, from: output!.extent)
let processedImage = UIImage(cgImage: cg cgImg mg!)
bg.image = processedImage
}或者在GitHub上有多个库,比如:https://github.com/FlexMonkey/Blurable
https://stackoverflow.com/questions/52055015
复制相似问题