Fix that the graphics helper method will return nil when scale = 0, match the UIKit behavior
This commit is contained in:
parent
f5cc328684
commit
ee6f99f204
|
@ -18,6 +18,10 @@
|
||||||
static void *kNSGraphicsContextScaleFactorKey;
|
static void *kNSGraphicsContextScaleFactorKey;
|
||||||
|
|
||||||
static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGFloat scale) {
|
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 width = ceil(size.width * scale);
|
||||||
size_t height = ceil(size.height * scale);
|
size_t height = ceil(size.height * scale);
|
||||||
if (width < 1 || height < 1) return NULL;
|
if (width < 1 || height < 1) return NULL;
|
||||||
|
@ -30,10 +34,6 @@ static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGF
|
||||||
if (!context) {
|
if (!context) {
|
||||||
return NULL;
|
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);
|
CGContextScaleCTM(context, scale, scale);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|
Loading…
Reference in New Issue