Last active
June 12, 2024 02:15
-
-
Save zappycode/3b5e151d4d98407901af5748745f5845 to your computer and use it in GitHub Desktop.
Coverting an NSImage into JPEG Data
This file contains 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
func jpegDataFrom(image:NSImage) -> Data { | |
let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)! | |
let bitmapRep = NSBitmapImageRep(cgImage: cgImage) | |
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])! | |
return jpegData | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @axayjha! Updated :)