]>
Commit | Line | Data |
---|---|---|
5e8ff485 RBR |
1 | import Cocoa |
2 | ||
3 | extension NSImage { | |
4 | public func writePNG(toURL url: URL) { | |
5 | ||
6 | guard let data = tiffRepresentation, | |
7 | let rep = NSBitmapImageRep(data: data), | |
8 | let imgData = rep.representation( | |
9 | using: .png, properties: [.compressionFactor: NSNumber(floatLiteral: 1.0)]) | |
10 | else { | |
11 | ||
12 | print( | |
13 | "\(self.self) Error Function '\(#function)' Line: \(#line) No tiff rep found for image writing to \(url)" | |
14 | ) | |
15 | return | |
16 | } | |
17 | ||
18 | do { | |
19 | try imgData.write(to: url) | |
20 | } catch let error { | |
21 | print( | |
22 | "\(self.self) Error Function '\(#function)' Line: \(#line) \(error.localizedDescription)") | |
23 | } | |
24 | } | |
25 | } |