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
Showing
1 changed file
with
10 additions
and
6 deletions
@@ -33,9 +33,6 @@ | @@ -33,9 +33,6 @@ | ||
33 | 33 | ||
34 | if (anyAlpha) { return image; } | 34 | if (anyAlpha) { return image; } |
35 | 35 | ||
36 | - size_t width = CGImageGetWidth(imageRef); | ||
37 | - size_t height = CGImageGetHeight(imageRef); | ||
38 | - | ||
39 | // current | 36 | // current |
40 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); | 37 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); |
41 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); | 38 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); |
@@ -44,10 +41,17 @@ | @@ -44,10 +41,17 @@ | ||
44 | if (unsupportedColorSpace) | 41 | if (unsupportedColorSpace) |
45 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); | 42 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); |
46 | 43 | ||
47 | - CGContextRef context = CGBitmapContextCreate(NULL, width, | 44 | + size_t width = CGImageGetWidth(imageRef); |
45 | + size_t height = CGImageGetHeight(imageRef); | ||
46 | + NSUInteger bytesPerPixel = 4; | ||
47 | + NSUInteger bytesPerRow = bytesPerPixel * width; | ||
48 | + NSUInteger bitsPerComponent = 8; | ||
49 | + | ||
50 | + CGContextRef context = CGBitmapContextCreate(NULL, | ||
51 | + width, | ||
48 | height, | 52 | height, |
49 | - CGImageGetBitsPerComponent(imageRef), | ||
50 | - 0, | 53 | + bitsPerComponent, |
54 | + bytesPerRow, | ||
51 | colorspaceRef, | 55 | colorspaceRef, |
52 | kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); | 56 | kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); |
53 | 57 |
-
Please register or login to post a comment