Search code examples
iphoneipadcore-graphicsquartz-graphicsquartz-2d

How can I easily change the overall opacity of a bitmap context using Quartz2D?


I'd like to create a fade out affect with one of my bitmap contexts that I use to draw a static image in one of my views. What's an easy way to adjust the overall opacity of the bitmap context on the fly before I render it to the view?

Thanks so much in advance for your help! I'm going to continue researching this right now.


Solution

  • If you are drawing the context (as an image) into another context, you can use this on the target context:

    CGContextSetAlpha( otherContext , ... );
    

    If the context will not otherwise change, you might just fade out the view (or layer) it is drawn in:

    view.alpha = ...;
    view.layer.opacity = ...;