From 4dbb15712b820e918206f8eeaf0a830894b404ca Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 23 Jun 2018 23:06:48 +0800 Subject: [PATCH] Fix that UIImage+Transform on macOS to use BGRA8888 instead of ARGB8888, as Apple's doc --- 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 323d4f44..5309bf72 100644 --- a/SDWebImage/UIImage+Transform.m +++ b/SDWebImage/UIImage+Transform.m @@ -14,14 +14,14 @@ #endif #if SD_MAC -static CGContextRef SDCGContextCreateARGBBitmapContext(CGSize size, BOOL opaque, CGFloat scale) { +static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGFloat scale) { size_t width = ceil(size.width * scale); size_t height = ceil(size.height * scale); if (width < 1 || height < 1) return NULL; - //pre-multiplied ARGB, 8-bits per component + //pre-multiplied BGRA, 8-bits per component, as Apple's doc CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); - CGImageAlphaInfo alphaInfo = (opaque ? kCGImageAlphaNoneSkipFirst : kCGImageAlphaPremultipliedFirst); + CGImageAlphaInfo alphaInfo = kCGBitmapByteOrder32Host | (opaque ? kCGImageAlphaNoneSkipFirst : kCGImageAlphaPremultipliedFirst); CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 0, space, kCGBitmapByteOrderDefault | alphaInfo); CGColorSpaceRelease(space); if (!context) { @@ -41,7 +41,7 @@ static void SDGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGF #if SD_UIKIT || SD_WATCH UIGraphicsBeginImageContextWithOptions(size, opaque, scale); #else - CGContextRef context = SDCGContextCreateARGBBitmapContext(size, opaque, scale); + CGContextRef context = SDCGContextCreateBitmapContext(size, opaque, scale); if (!context) { return; }