Created
May 29, 2015 14:00
-
-
Save hinzundcode/2ca9b9a425b8ed0d9ec4 to your computer and use it in GitHub Desktop.
NSImage to base64 encoded data url
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
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