From eaaba1cffc9b804c5622739df70a33913d4087d5 Mon Sep 17 00:00:00 2001 From: Murtaza Javaid Date: Thu, 14 Dec 2023 20:02:37 +0400 Subject: [PATCH] Remove deprecated UIGraphicsBeginImageContext --- Sources/SnapshotTesting/Snapshotting/UIImage.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/SnapshotTesting/Snapshotting/UIImage.swift b/Sources/SnapshotTesting/Snapshotting/UIImage.swift index e5fc4262e..b278f0742 100644 --- a/Sources/SnapshotTesting/Snapshotting/UIImage.swift +++ b/Sources/SnapshotTesting/Snapshotting/UIImage.swift @@ -182,12 +182,13 @@ let width = max(old.size.width, new.size.width) let height = max(old.size.height, new.size.height) let scale = max(old.scale, new.scale) - UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), true, scale) - new.draw(at: .zero) - old.draw(at: .zero, blendMode: .difference, alpha: 1) - let differenceImage = UIGraphicsGetImageFromCurrentImageContext()! - UIGraphicsEndImageContext() - return differenceImage + let format = UIGraphicsImageRendererFormat() + format.scale = scale + format.opaque = true + return UIGraphicsImageRenderer(size: CGSize(width: width, height: height), format: format).image { _ in + new.draw(at: .zero) + old.draw(at: .zero, blendMode: .difference, alpha: 1) + } } #endif