Skip to content

Instantly share code, notes, and snippets.

View axayjha's full-sized avatar
🚀
work hard, play hard

Akshay Anand axayjha

🚀
work hard, play hard
View GitHub Profile
@zappycode
zappycode / NSImageToJpeg.swift
Last active June 12, 2024 02:15
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
}