Skip to content

Instantly share code, notes, and snippets.

@hinzundcode
Created May 29, 2015 14:00
Show Gist options
  • Save hinzundcode/2ca9b9a425b8ed0d9ec4 to your computer and use it in GitHub Desktop.
Save hinzundcode/2ca9b9a425b8ed0d9ec4 to your computer and use it in GitHub Desktop.
NSImage to base64 encoded data url
var path: NSString = NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier("com.apple.dt.xcode")!
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)
println(base64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment