]> git.r.bdr.sh - rbdr/map/blame - Map/Extensions/NSImage+writePNG.swift
Add sidebar menu
[rbdr/map] / Map / Extensions / NSImage+writePNG.swift
CommitLineData
5e8ff485
RBR
1import Cocoa
2
3extension 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}