Skip to content

Instantly share code, notes, and snippets.

@cuxaro
Created October 19, 2016 15:01
Show Gist options
  • Save cuxaro/20a5b9bbbccc46180861e01aa7f4a267 to your computer and use it in GitHub Desktop.
Save cuxaro/20a5b9bbbccc46180861e01aa7f4a267 to your computer and use it in GitHub Desktop.
Resize Image with Swift 3
func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {
let scale = newWidth / image.size.width
let newHeight = image.size.height * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
image.draw(in: CGRect(x: 0, y: 0,width: newWidth, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
func resizeToScreenSize(image: UIImage)->UIImage{
let screenSize = self.view.bounds.size
return resizeImage(image: image, newWidth: screenSize.width)
}
@bigmit2011
Copy link

What interpolation method is used to resize? Is there any way to choose different interpolation methods? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment