小编Jav*_*ont的帖子

UIGraphicsGetImageFromCurrentImageContext() 返回 nil

我有这个 UIImage 的扩展:

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!
 }
}
Run Code Online (Sandbox Code Playgroud)

为什么 UIGraphicsGetImageFromCurrentImageContext 返回 nil?跟图片大小有关系吗?

(lldb) po self.size ?(3024.0, 4032.0) - 宽度:3024.0 - 高度:4032.0

在此处输入图片说明

uiimage ios swift

6
推荐指数
1
解决办法
3684
查看次数

标签 统计

ios ×1

swift ×1

uiimage ×1