Show Blended Layers reveals red UIImage but it does not have an alpha channel
ios, objective-c, uiimage, uiimageview, uiscrollview
Solution
By default, `UIImage` instances are rendered in a Graphic Context that includes alpha channel. To avoid it, you need to generate another image using a new Graphic Context where `opaque = YES`.
- (UIImage *)optimizedImageFromImage:(UIImage *)image
{
CGSize imageSize = image.size;
UIGraphicsBeginImageContextWithOptions( imageSize, opaque, scale );
[image drawInRect: CGRectMake( 0, 0, imageSize.width, imageSize.height )];
UIImage *optimizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return optimizedImage;
}
Problem
I have an image that does not have an alpha channel - I confirmed in Finder's Get Info panel. Yet when I put it in a `UIImageView` which is within a `UIScrollView` and I enable Show Blended Layers, the image is red which indicates it's trying to apply transparency which will be a hit on performance. How can fix this to be green so iOS knows everything in this view is fully opaque? I tried the following but this did not remove the red color: ``` self.imageView.opaque = YES; self.scrollView.opaque = YES; ```