Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
NSImage to base64 encoded data url
var path: NSString = NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier("")!
var icon: NSImage = NSWorkspace.sharedWorkspace().iconForFile(path)
var data: NSData = icon.TIFFRepresentation!
var bitmap: NSBitmapImageRep = NSBitmapImageRep(data: data)!
data = bitmap.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:])!
var base64: NSString = "data:image/png;base64," + data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment