Created
July 10, 2020 19:46
-
-
Save rintoandrews90/37ed0b80e49699f9f1b3f7a761a000f6 to your computer and use it in GitHub Desktop.
This file contains 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
func downsample(imageURL: URL, to pointSize: CGSize, scale: CGFloat) -> UIImage { | |
let imgeSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary | |
let imageSource = CGImageSourceCreateWithURL(imageURL as CFURL, imgeSourceOptions)! | |
let maxDimensionInPixel = max(pointSize.width, pointSize.height) * scale | |
let downsampleOptions = [ | |
kCGImageSourceCreateThumbnailFromImageAlways: true, | |
kCGImageSourceShouldCacheImmediately: true, | |
kCGImageSourceCreateThumbnailWithTransform: true, | |
kCGImageSourceThumbnailMaxPixelSize: maxDimensionInPixel | |
] as CFDictionary | |
let downsampledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, downsampleOptions)! | |
return UIImage(cgImage: downsampledImage) | |
} | |
let image = self?.downsample(imageURL: filename, to: CGSize(width: 50, height: 50), scale: 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment