swift UIGraphicsGetImageFromCurrentImageContext can't release memory

前端 未结 2 1015
清歌不尽
清歌不尽 2021-02-05 08:39

Swift Code

When we get a screenshot of a UIView, we use this code usually:

UIGraphicsBeginImageContextWithOptions(frame.size, false, scale)
drawViewHie         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 08:55

    private extension UIImage
    {
        func resized() -> UIImage {
            let height: CGFloat = 800.0
            let ratio = self.size.width / self.size.height
            let width = height * ratio
    
            let newSize = CGSize(width: width, height: height)
            let newRectangle = CGRect(x: 0, y: 0, width: width, height: height)
    
            UIGraphicsBeginImageContext(newSize)
            self.draw(in: newRectangle)
    
            let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
    
            return resizedImage!
        } 
    }
    

提交回复
热议问题