Merge pull request #1496 from yamasakitomohiro/master

fixes  CGContextDrawImage: invalid context 0x0
https://github.com/rs/SDWebImage/issues/1401
https://github.com/rs/SDWebImage/issues/1454
https://github.com/rs/SDWebImage/issues/1457
This commit is contained in:
Konstantinos K 2016-03-17 09:46:40 +02:00
commit 1ef791bad9
1 changed files with 17 additions and 13 deletions

View File

@ -33,9 +33,6 @@
if (anyAlpha) { return image; }
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
// current
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
@ -44,10 +41,17 @@
if (unsupportedColorSpace)
colorspaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width,
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(NULL,
width,
height,
CGImageGetBitsPerComponent(imageRef),
0,
bitsPerComponent,
bytesPerRow,
colorspaceRef,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);