in Diffusion-macOS/ContentView.swift [36:48]
func savePNG(cgImage: CGImage, path: URL) {
let image = NSImage(cgImage: cgImage, size: .zero)
let imageRepresentation = NSBitmapImageRep(data: image.tiffRepresentation!)
guard let pngData = imageRepresentation?.representation(using: .png, properties: [:]) else {
print("Error generating PNG data")
return
}
do {
try pngData.write(to: path)
} catch {
print("Error saving: \(error)")
}
}