From 0691a382c2dd6f2ba2c195a994e68ba8c0d23d60 Mon Sep 17 00:00:00 2001 From: onevcat Date: Tue, 11 Apr 2017 11:17:38 +0900 Subject: [PATCH] Crop scaled rect for CGImage --- Sources/Image.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/Image.swift b/Sources/Image.swift index ff46ee7f6..c13252355 100755 --- a/Sources/Image.swift +++ b/Sources/Image.swift @@ -437,7 +437,7 @@ extension Kingfisher where Base: Image { } let rect = self.size.kf.constrainedRect(for: size, anchor: anchor) - guard let image = cgImage.cropping(to: rect) else { + guard let image = cgImage.cropping(to: rect.scaled(scale)) else { assertionFailure("[Kingfisher] Cropping image failed.") return base } @@ -747,6 +747,13 @@ extension CGSizeProxy { } } +extension CGRect { + func scaled(_ scale: CGFloat) -> CGRect { + return CGRect(x: origin.x * scale, y: origin.y * scale, + width: size.width * scale, height: size.height * scale) + } +} + extension Comparable { func clamped(to limits: ClosedRange) -> Self { return min(max(self, limits.lowerBound), limits.upperBound)