• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Remove alpha channel from uiimage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Remove alpha channel from uiimage


  • Subject: Remove alpha channel from uiimage
  • From: Peng Gu <email@hidden>
  • Date: Tue, 28 Jan 2014 15:37:49 -0500

I use the following method to get a decompressed uiimage from file system.
However the UIImageView is colored as red when I turn on the color blended
layer, even though the UIImageView is set to Opaque.

The images on file system don't have alpha channel. I tried set
CGContextSetAlpha(bitmapContext, 1), but still has blended layer.

Anyone know how to remove 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
                                                       );
    // kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little are the
bit flags required
    //  so that the main thread doesn't have any conversions to do.

    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;
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Remove alpha channel from uiimage
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: Cocoa app screen update issues on Mavericks
  • Next by Date: Re: Remove alpha channel from uiimage
  • Previous by thread: Job listing: Cocoa/CoreAudio Contract
  • Next by thread: Re: Remove alpha channel from uiimage
  • Index(es):
    • Date
    • Thread