]> git.r.bdr.sh - rbdr/map/blob - Map/Extensions/NSImage+writePNG.swift
c24c0cf4c5f4209a94bd77bbd6c17b3cf503fb88
[rbdr/map] / Map / Extensions / NSImage+writePNG.swift
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 }