Skip to content

Instantly share code, notes, and snippets.

@zappycode
Last active June 12, 2024 02:15
Show Gist options
  • Save zappycode/3b5e151d4d98407901af5748745f5845 to your computer and use it in GitHub Desktop.
Save zappycode/3b5e151d4d98407901af5748745f5845 to your computer and use it in GitHub Desktop.
Coverting an NSImage into JPEG Data
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
}
@zappycode
Copy link
Author

Thanks @axayjha! Updated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment