Updated for Swift 3, this is a convenience feature that takes a CGContext and returns a UIImage. Note that you no longer need to free the context when you are done with it in Swift 3.
func imageFromContext(_ context: CGContext) -> UIImage? { guard let cgImage = context.makeImage() else { return nil } return UIImage.init(cgImage: cgImage) }
Echelon
source share