Skip to content

Instantly share code, notes, and snippets.

@algal
Created July 10, 2015 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save algal/2fa41db7a5b61e366446 to your computer and use it in GitHub Desktop.
Save algal/2fa41db7a5b61e366446 to your computer and use it in GitHub Desktop.
Save a UIImage into a URL
/// Save image in an in-memory URL
func toURL(image:UIImage) -> NSURL
{
let img = image
let imgData:NSData = UIImagePNGRepresentation(img)
let dataFormatString = "data:image/png;base64,%@"
let dataString = String(format: dataFormatString, imgData.base64EncodedStringWithOptions(.allZeros))
let dataURL = NSURL(string: dataString)!
return dataURL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment