У меня есть это расширение Uiimage: < /p>
extension UIImage {
func resizeImage(newWidth: CGFloat, newHeight: CGFloat? = nil) -> UIImage {
let scale = newWidth / self.size.width
let finalHeight = (newHeight == nil) ? self.size.height * scale : newHeight!
UIGraphicsBeginImageContextWithOptions(CGSize(width:newWidth, height: finalHeight), false, self.scale)
self.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: finalHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
}
< /code>
Почему uicraphicsGetImageFromCurrentImageContext возвращается нуль? Имеет ли это какое -то отношение к размеру изображения? src = "https://i.sstatic.net/ciwxy.png"/>
Подробнее здесь: https://stackoverflow.com/questions/461 ... eturns-nil