使用Swift 5 xcode 13将屏幕截图保存为pdf或高分辨率图像



在这里找到:如何在Swift中拍摄全屏截图?

func getScreenshot() -> UIImage {
var window: UIWindow? = UIApplication.shared.keyWindow
window = UIApplication.shared.windows[0] as? UIWindow
UIGraphicsBeginImageContextWithOptions(window!.frame.size, window!.isOpaque, 0.0)
window!.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}

我的图片包含了很多DIN A4格式的文本。打印出来的图像质量很差。有机会提高分辨率吗?

最好的方法是将屏幕截图保存为pdf。这里有什么帮助来保存和重新整理我的设备中的image.pdf吗。

谢谢任何提示。

只需通过PDFKit 将您的图像转换为pdf即可

import PDFKit
let pdfPage = PDFPage(image: screenshotImage) 
let fm = FileManager.default urls = fm.urls(for: .documentDirectory, in: .userDomainMask).first! 
let savedPDF = urls!.appendingPathComponent("pdfPage.pdf") pdfPage?.document?.write(toFile: "pdfPage")

最新更新