Skip to content

Instantly share code, notes, and snippets.

@zhaorui
Created October 17, 2016 09:28
Show Gist options
  • Save zhaorui/016f7f91726d05803762b0d1df05ddd4 to your computer and use it in GitHub Desktop.
Save zhaorui/016f7f91726d05803762b0d1df05ddd4 to your computer and use it in GitHub Desktop.
let image = UIImage(named: "car.jpg")
let hasAlpha = false
let scale: CGFloat = 0.0 // Automatically use scale factor of main screen
UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height:80), !hasAlpha, scale)
image?.draw(in: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 80, height: 80)))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment