Created
November 29, 2015 10:25
-
-
Save westerlund/e1b99e21615bb18bc380 to your computer and use it in GitHub Desktop.
Write NSImage to disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSImage { | |
func writeToFile(file: String, atomically: Bool, usingType type: NSBitmapImageFileType) -> Bool { | |
let properties = [NSImageCompressionFactor: 1.0] | |
guard | |
let imageData = TIFFRepresentation, | |
imageRep = NSBitmapImageRep(data: imageData), | |
fileData = imageRep.representationUsingType(type, properties: properties) else { | |
return false | |
} | |
return fileData.writeToFile(file, atomically: atomically) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: