From fdb4633d3e9158e457d57e820df6e1efb4df39c2 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Sun, 7 May 2023 15:22:54 +0200 Subject: Update to support notes + new style --- Map/Core Extensions/NSImage+writePNG.swift | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Map/Core Extensions/NSImage+writePNG.swift (limited to 'Map/Core Extensions/NSImage+writePNG.swift') diff --git a/Map/Core Extensions/NSImage+writePNG.swift b/Map/Core Extensions/NSImage+writePNG.swift new file mode 100644 index 0000000..c24c0cf --- /dev/null +++ b/Map/Core Extensions/NSImage+writePNG.swift @@ -0,0 +1,25 @@ +import Cocoa + +extension NSImage { + public func writePNG(toURL url: URL) { + + guard let data = tiffRepresentation, + let rep = NSBitmapImageRep(data: data), + let imgData = rep.representation( + using: .png, properties: [.compressionFactor: NSNumber(floatLiteral: 1.0)]) + else { + + print( + "\(self.self) Error Function '\(#function)' Line: \(#line) No tiff rep found for image writing to \(url)" + ) + return + } + + do { + try imgData.write(to: url) + } catch let error { + print( + "\(self.self) Error Function '\(#function)' Line: \(#line) \(error.localizedDescription)") + } + } +} -- cgit v1.2.3-70-g09d2