-
- private func saveImage() {
- if let image = document.exportAsImage(withEvolution: selectedEvolution) {
-
- let filename = url?.deletingPathExtension().lastPathComponent ?? "Untitled"
-
- let savePanel = NSSavePanel()
- savePanel.allowedContentTypes = [.png]
- savePanel.canCreateDirectories = true
- savePanel.isExtensionHidden = false
- savePanel.title = "Save \(filename) as image"
- savePanel.message = "Choose a location to save the image"
- savePanel.nameFieldStringValue = "\(filename).png"
- savePanel.begin { result in
- if result == .OK, let url = savePanel.url {
- if let tiffRepresentation = image.tiffRepresentation {
- let bitmapImage = NSBitmapImageRep(data: tiffRepresentation)
- let pngData = bitmapImage?.representation(using: .png, properties: [:])
- do {
- try pngData?.write(to: url)
- } catch {
- return
- }
- }
- }
- }
- }
- }