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 t开发者_Python百科o the view?
Thanks so much in advance for your help! I'm going to continue researching this right now.
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 = ...;
You could use CGContextSetAlpha() before drawing the CGImageRef (and save and restore context state around that drawing) to modify the alpha of the image as it is being drawn.
However, you would likely find better performance by putting the image in its own view (by using a UIImageView for example) and using an animation to adjust the opacity.
精彩评论