Last active
April 9, 2017 18:47
-
-
Save appshish/e89a6369dcf02ddc77c2 to your computer and use it in GitHub Desktop.
Resize Image in iOS Swift
This file contains 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
// Courtesy: Hampton Catlin's gist. | |
// to resize an image to dimension 52x52 | |
var newSize:CGSize = CGSize(width: 52,height: 52) | |
let rect = CGRectMake(0,0, newSize.width, newSize.height) | |
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) | |
// image is a variable of type UIImage | |
image?.drawInRect(rect) | |
let newImage = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
// resized image is stored in constant newImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment