From 7e3482d4fc43e63116254b98f4f49dec34f94266 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 15 Jan 2020 11:56:19 +0800 Subject: [PATCH] Fix the issue of `CGImageCreateScaled`, which should use BGRX8888 on non-alpha image, BGRA8888 on alpha image --- SDWebImage/Core/SDImageCoderHelper.m | 7 +++++-- SDWebImage/Core/UIImage+Transform.m | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/SDImageCoderHelper.m b/SDWebImage/Core/SDImageCoderHelper.m index de3d0cfc..c29685a9 100644 --- a/SDWebImage/Core/SDImageCoderHelper.m +++ b/SDWebImage/Core/SDImageCoderHelper.m @@ -293,12 +293,15 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over if (input_buffer.data) free(input_buffer.data); if (output_buffer.data) free(output_buffer.data); }; - + BOOL hasAlpha = [self CGImageContainsAlpha:cgImage]; + // iOS display alpha info (BGRA8888/BGRX8888) + CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host; + bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst; vImage_CGImageFormat format = (vImage_CGImageFormat) { .bitsPerComponent = 8, .bitsPerPixel = 32, .colorSpace = NULL, - .bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrderDefault, + .bitmapInfo = bitmapInfo, .version = 0, .decode = NULL, .renderingIntent = kCGRenderingIntentDefault, diff --git a/SDWebImage/Core/UIImage+Transform.m b/SDWebImage/Core/UIImage+Transform.m index 53fc334c..b1c3fc13 100644 --- a/SDWebImage/Core/UIImage+Transform.m +++ b/SDWebImage/Core/UIImage+Transform.m @@ -606,7 +606,7 @@ static inline CGImageRef _Nullable SDCreateCGImageFromCIImage(CIImage * _Nonnull .bitsPerComponent = 8, .bitsPerPixel = 32, .colorSpace = NULL, - .bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little, //requests a BGRA buffer. + .bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, //requests a BGRA buffer. .version = 0, .decode = NULL, .renderingIntent = kCGRenderingIntentDefault