Merge pull request #1236 from mythodeia/master
better handling of colorspace models
This commit is contained in:
commit
0df58e4995
|
@ -29,11 +29,17 @@
|
||||||
size_t width = CGImageGetWidth(imageRef);
|
size_t width = CGImageGetWidth(imageRef);
|
||||||
size_t height = CGImageGetHeight(imageRef);
|
size_t height = CGImageGetHeight(imageRef);
|
||||||
|
|
||||||
|
// default RGB
|
||||||
|
CGColorSpaceRef RGBcolorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
|
|
||||||
|
// current
|
||||||
|
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
|
||||||
|
|
||||||
CGContextRef context = CGBitmapContextCreate(NULL, width,
|
CGContextRef context = CGBitmapContextCreate(NULL, width,
|
||||||
height,
|
height,
|
||||||
CGImageGetBitsPerComponent(imageRef),
|
CGImageGetBitsPerComponent(imageRef),
|
||||||
0,
|
0,
|
||||||
CGImageGetColorSpace(imageRef),
|
(imageColorSpaceModel == 0 || imageColorSpaceModel == -1) ? RGBcolorSpace : CGImageGetColorSpace(imageRef),
|
||||||
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
|
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
|
||||||
|
|
||||||
// Draw the image into the context and retrieve the new image, which will now have an alpha layer
|
// Draw the image into the context and retrieve the new image, which will now have an alpha layer
|
||||||
|
@ -41,6 +47,7 @@
|
||||||
CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context);
|
CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context);
|
||||||
UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha];
|
UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha];
|
||||||
|
|
||||||
|
CGColorSpaceRelease(RGBcolorSpace);
|
||||||
CGContextRelease(context);
|
CGContextRelease(context);
|
||||||
CGImageRelease(imageRefWithAlpha);
|
CGImageRelease(imageRefWithAlpha);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue