【发布时间】:2021-11-25 13:11:38
【问题描述】:
在照片编辑器屏幕中,我有 imageview,它有背景图像,在 imageview 顶部我添加了文本(标签)、贴纸(图像)等元素,现在对于包含添加到 imageview 上的所有元素的最终图像,我我正在从下面的代码中获取图像
clipRect 是 imageview 中背景图像的矩形,图像是 imageview 中的 aspectfit
下面是 UIView 扩展中的代码,它具有生成视图之外的图像的功能。
self == uiview
let op_format = UIGraphicsImageRendererFormat()
op_format.scale = 1.0
let renderer = UIGraphicsImageRenderer(bounds: CGRect(origin: clipRect!.origin, size: outputSize), format: op_format)
let originalBound = self.bounds
self.bounds = CGRect(origin: clipRect!.origin, size: clipRect!.size)
var finalImage = renderer.image { ctx in
self.drawHierarchy(in: CGRect(origin: self.bounds.origin, size: outputSize), afterScreenUpdates: true)
}
self.bounds = CGRect(origin: originalBound.origin, size: originalBound.size)
这里的问题是最终图像质量与原始背景图像相比非常差。
【问题讨论】:
-
这里的问题是不存在
UIImgeView对象,无论标题是什么。 -
@ElTomato 为了更清楚添加细节,代码在 uiview 扩展的函数内
标签: ios swift image-processing uiimageview uikit