From 636a8a23f808d8b98732d059a776ed201ab0b2b8 Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Sat, 30 Mar 2024 22:33:41 +0800 Subject: [PATCH] adjust iOS 17 to use image generate pdf file --- Source/Internal/Graphics/PDFGraphics.swift | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/Internal/Graphics/PDFGraphics.swift b/Source/Internal/Graphics/PDFGraphics.swift index af298f18..df94bdf7 100644 --- a/Source/Internal/Graphics/PDFGraphics.swift +++ b/Source/Internal/Graphics/PDFGraphics.swift @@ -183,12 +183,21 @@ internal enum PDFGraphics { height: floor(frame.height * resizeFactor)) #if os(iOS) - UIGraphicsBeginImageContext(size) - image.draw(in: CGRect(origin: .zero, size: size)) - let finalImage = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - - return finalImage ?? image + var finalImage: UIImage = image + if #available(iOS 17.0, *) { + if let cgImage = image.cgImage { + finalImage = UIGraphicsImageRenderer(size: size).image { renderContext in + let rect = CGRect(origin: .zero, size: size) + renderContext.cgContext.draw(image: cgImage, in: rect, flipped: true) + } + } + } else { + UIGraphicsBeginImageContext(size) + image.draw(in: CGRect(origin: .zero, size: size)) + finalImage = UIGraphicsGetImageFromCurrentImageContext() ?? image + UIGraphicsEndImageContext() + } + return finalImage #elseif os(macOS) let finalImage = NSImage(size: size) finalImage.lockFocus()