Search code examples
ioscore-graphics

How to copy one CGContextRef to another?


in -drawRect:, I created a secondary CGContextRef using CGBitmapContextCreate().

When I'm done with this context, I need to copy it's contents over to the "original" context of -drawRect:. How can I do that?

Reason why I create an additional context: I hope to get CGContextClipToMask() to work in a view that has a transparent background. My idea is to do all the mask-drawing and clipping in another context that has the appropriate color (non-transparent, no alpha), and then somehow paste that result back to the original context.


Solution

  • you can use memcpy function. Read on google for how to use it.