Last active
February 27, 2018 09:46
-
-
Save zlq4863947/ac95715a1c4d1e548debb7615f714732 to your computer and use it in GitHub Desktop.
【Swift4】UIImageで画像のサイズ変更、指定した倍率で拡大/縮小 ref: https://qiita.com/zlq4863947/items/4b016824cf152bc2a769
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
extension UIImage { | |
// resize image | |
func reSizeImage(reSize:CGSize)->UIImage { | |
//UIGraphicsBeginImageContext(reSize); | |
UIGraphicsBeginImageContextWithOptions(reSize,false,UIScreen.main.scale); | |
self.draw(in: CGRect(x: 0, y: 0, width: reSize.width, height: reSize.height)); | |
let reSizeImage:UIImage! = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return reSizeImage; | |
} | |
// scale the image at rates | |
func scaleImage(scaleSize:CGFloat)->UIImage { | |
let reSize = CGSize(width: self.size.width * scaleSize, height: self.size.height * scaleSize) | |
return reSizeImage(reSize: reSize) | |
} | |
} |
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
let reSize = CGSize(width: self.size.width * scaleSize, height: self.size.height * scaleSize) | |
image?.reSizeImage(reSize: reSize) |
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
image?.scaleImage(scaleSize: 0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment