Skip to content

Instantly share code, notes, and snippets.

@leviathan
Last active January 22, 2020 07:35
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 leviathan/c44c6971c48dca055266c831e1e16e71 to your computer and use it in GitHub Desktop.
Save leviathan/c44c6971c48dca055266c831e1e16e71 to your computer and use it in GitHub Desktop.
UIImage quick file dump
/// Quickly dump a UIImage from memory into a tmp file.
var image: UIImage?
// ...
let imageFilePath = NSTemporaryDirectory() + "\(Date().timeIntervalSince1970).png"
try? image.pngData()!.write(to: URL(fileURLWithPath: imageFilePath))
print("Saved turn-by-turn advice image to: \(imageFilePath)")
/// UIView to UIImage
let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
let image = renderer.image { ctx in
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment