I use the following method to get the unpacked uiimage from the file system. However, the UIImageView is red when I turn on the color mixed layer, even if the UIImageView is set to Opaque.
Images in the file system do not have an alpha channel. I tried setting CGContextSetAlpha (bitmapContext, 1) but still has a mixed layer.
Does anyone know how to remove an alpha channel when using CGContextDrawImage?
- (UIImage *)decompressedImage
{
CGImageRef imageRef = self.CGImage;
CGRect rect = CGRectMake(0.f, 0.f, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
rect.size.width,
rect.size.height,
CGImageGetBitsPerComponent(imageRef),
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little
);
CGContextDrawImage(bitmapContext, rect, imageRef);
CGImageRef decompressedImageRef = CGBitmapContextCreateImage(bitmapContext);
UIImage* decompressedImage = [UIImage imageWithCGImage:decompressedImageRef
scale:[[UIScreen mainScreen] scale]
orientation:UIImageOrientationUp];
CGImageRelease(decompressedImageRef);
CGContextRelease(bitmapContext);
return decompressedImage;
}
source
share