Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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