Resize Image without losing quality

后端 未结 4 950
天命终不由人
天命终不由人 2021-01-02 04:50

I\'m using the functions below to resize my images width & height but I noticed that it ruins the image quality.

class func imageWithSize(image: UIImage,         


        
4条回答
  •  囚心锁ツ
    2021-01-02 05:22

    Here is my code in swift. For squared images, it works really well and without any loss of quality!

    extension UIImage {
    
        func resize(targetSize: CGSize) -> UIImage {
            return UIGraphicsImageRenderer(size:targetSize).image { _ in
                self.draw(in: CGRect(origin: .zero, size: targetSize))
            }
        }
    
    }
    

提交回复
热议问题