From ee6f99f204d878b01be5b17fd0d3a0f47c69d005 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 31 Oct 2018 14:40:10 +0800 Subject: [PATCH] Fix that the graphics helper method will return nil when scale = 0, match the UIKit behavior --- SDWebImage/UIImage+Transform.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SDWebImage/UIImage+Transform.m b/SDWebImage/UIImage+Transform.m index ff95ea45..a397924a 100644 --- a/SDWebImage/UIImage+Transform.m +++ b/SDWebImage/UIImage+Transform.m @@ -18,6 +18,10 @@ static void *kNSGraphicsContextScaleFactorKey; static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGFloat scale) { + if (scale == 0) { + // Match `UIGraphicsBeginImageContextWithOptions`, reset to the scale factor of the device’s main screen if scale is 0. + scale = [NSScreen mainScreen].backingScaleFactor; + } size_t width = ceil(size.width * scale); size_t height = ceil(size.height * scale); if (width < 1 || height < 1) return NULL; @@ -30,10 +34,6 @@ static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGF if (!context) { return NULL; } - if (scale == 0) { - // Match `UIGraphicsBeginImageContextWithOptions`, reset to the scale factor of the device’s main screen if scale is 0. - scale = [NSScreen mainScreen].backingScaleFactor; - } CGContextScaleCTM(context, scale, scale); return context;