Created
October 19, 2016 15:01
-
-
Save cuxaro/20a5b9bbbccc46180861e01aa7f4a267 to your computer and use it in GitHub Desktop.
Resize Image with Swift 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What interpolation method is used to resize? Is there any way to choose different interpolation methods? Thanks!