This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Image downsampling technique provides smaller image buffer allocations which leads to memory optimization | |
extension UIImageView { | |
func downsampleImage(from imageUrl: URL) -> UIImage { | |
let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary | |
guard let imageSource = CGImageSourceCreateWithURL(imageUrl as CFURL, imageSourceOptions) else { return UIImage() } | |
let maxDimensionInPixels = max(self.bounds.size.width, self.bounds.size.height) * self.traitCollection.displayScale | |
let downsampleOptions = | |
[kCGImageSourceCreateThumbnailFromImageAlways: true, |