Forked from anupamchugh/resizedImage-UIImage+Extension.swift
Created
October 8, 2021 18:18
-
-
Save vukcevich/9c70c25c11695079cb9adccf4086b6bf 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 resizedImage(for size: CGSize) -> UIImage? { | |
let image = self.cgImage | |
let context = CGContext(data: nil, | |
width: Int(size.width), | |
height: Int(size.height), | |
bitsPerComponent: image!.bitsPerComponent, | |
bytesPerRow: Int(size.width), | |
space: image?.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!, | |
bitmapInfo: image!.bitmapInfo.rawValue) | |
context?.interpolationQuality = .high | |
context?.draw(image!, in: CGRect(origin: .zero, size: size)) | |
guard let scaledImage = context?.makeImage() else { return nil } | |
return UIImage(cgImage: scaledImage) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment