Copy CGContext into another CGContext Copy CGContext into another CGContext objective-c objective-c

Copy CGContext into another CGContext


You could use a CGLayerRef. The layer ref is like sub-context that you do a bunch of drawing into, and then flatten down into the original context when you finish drawing the layer's worth of content.

It's typically used to get shared alpha or shadows across many drawing calls rather than each individual call.

I don't know if this will still workaround whatever bug you're encountering, or whether the performance is better or worse than the two context approach. I'd need to know more about your goals and requirements. For example, do you you want to avoid using two context to avoid a second copy, or because you don't want to pay the memory for the second image?


the actual physical copy of the bits occur only if the underlying data in the bitmap graphics context is modified when you use CGBitmapContextCreateImage, so there is not much performance loss when you create an image from the CGBitmapContext.