Skip to content

Commit

Permalink
feat: support save image as
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Dec 24, 2023
1 parent 993af53 commit da52882
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions PhotosProcessor/Backend/ProcessImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,30 @@ class ProcessImage: NSObject, ObservableObject {
print("[I] Refreshed image: \(self.url!)")
self.setup(url: self.url!)
}

func saveAs() {
if !self.inited {
print("[W] Image not inited. SaveAs failed.")
return
}
InternalKit.saveFilePanel(title: "Save Image", message: "Save the image file", action: { url in
if url == nil {
print("[E] No image selected")
return
}
let cgImage = self.image?.cgImage(forProposedRect: nil, context: nil, hints: nil)
if cgImage == nil {
print("[E] Failed to get cgImage")
return
}
let bitmapRep = NSBitmapImageRep(cgImage: cgImage!)
let data = bitmapRep.representation(using: .png, properties: [:])
do {
try data?.write(to: url!)
} catch {
print("[E] Failed to write image to file: \(error)")
return
}
})
}
}

0 comments on commit da52882

Please sign in to comment.