Skip to content

Instantly share code, notes, and snippets.

@mbarriault
Created May 31, 2016 16:18
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 mbarriault/82aaee5bef05fc73919a3115a7bb7f64 to your computer and use it in GitHub Desktop.
Save mbarriault/82aaee5bef05fc73919a3115a7bb7f64 to your computer and use it in GitHub Desktop.
let scaledImage: UIImage
do {
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
defer {
UIGraphicsEndImageContext()
}
// Fill background
UIColor.blackColor().setFill(); UIRectFill(CGRect(origin: .zero, size: size))
// Draw scaled image
let drawingRect: CGRect = CGRect(
origin: drawingOrigin,
size: CGSize(width: scaledWidth, height: scaledHeight))
image.drawInRect(drawingRect)
// Fetch image
scaledImage = UIGraphicsGetImageFromCurrentImageContext()!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment