【发布时间】:2019-02-02 22:03:04
【问题描述】:
我使用 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 转换为 image 后,模糊的图像几乎不会模糊,因为我增加了容器视图的大小。
您能为这个问题提出一个解决方案吗? 我只是想得到一个模糊的图像,所以如果你知道使用滑块模糊图像的其他方法(模糊代码应该可以快速运行,因此 UI 不会冻结),请告诉我。
【问题讨论】:
-
您是否尝试过不调整
imageContainerView的大小并将UIGraphicsBeginImageContextWithOptions的scale参数设置为0(这将自动匹配设备的比例因子你正在使用)?UIGraphicsBeginImageContextWithOptions(imageContainerView.bounds.size, true, 0) -
你能解释一下有什么区别吗?假设设备的比例因子为 2,因此它将使 containerView 的大小翻倍。如果我手动操作有什么区别?
标签: ios swift xcode image-processing blur