In my iPhone app, I take a picture with the camera, then I want to resize it to 290*390 pixels. I was using this method to resize the image :
UIImage *newI
Use this extension, in case you need to resize width/height only with aspect ratio.
extension UIImage {
func resize(to size: CGSize) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { _ in
draw(in: CGRect(origin: .zero, size: size))
}
}
func resize(width: CGFloat) -> UIImage {
return resize(to: CGSize(width: width, height: width / (size.width / size.height)))
}
func resize(height: CGFloat) -> UIImage {
return resize(to: CGSize(width: height * (size.width / size.height), height: height))
}
}