我有一个长的日历屏幕滚动并尝试共享完整日历的完整屏幕截图,使用了此扩展名,但在iPhone 8加上真实设备上获得了202x1024的不良图像质量。我如何获得完整的分辨率屏幕截图,包括屏幕的滚动区域。
fileprivate extension UITableView {
func screenshot() -> UIImage? {
let savedContentOffset = contentOffset
let savedFrame = frame
UIGraphicsBeginImageContext(contentSize)
contentOffset = .zero
frame = CGRect(x: 0, y: 0, width: contentSize.width, height: contentSize.height)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
layer.render(in: context)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
contentOffset = savedContentOffset
frame = savedFrame
return image
}
}
您是否尝试过为图像上下文指定刻度?
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)