Skip to content

Commit a7af2a1

Browse files
author
Olivier Poitrey
committed
Try to fix decode image error message
1 parent 6e99059 commit a7af2a1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

SDWebImage/SDWebImageDecoder.m

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ + (UIImage *)decodedImageWithImage:(UIImage *)image
1717
CGImageRef imageRef = image.CGImage;
1818
CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
1919
CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize};
20-
20+
2121
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
22-
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
23-
CGContextRef context;
24-
context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, imageSize.width * 4, colorSpace, bitmapInfo);
22+
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpace, CGImageGetBitmapInfo(imageRef));
2523
CGColorSpaceRelease(colorSpace);
26-
27-
if (!context) return nil;
24+
25+
// If failed, return undecompressed image
26+
if (!context) return image;
2827

2928
CGContextDrawImage(context, imageRect, imageRef);
3029
CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context);

0 commit comments

Comments
 (0)