Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz 2D: draw from a CGContext to another CGContext

I have a CGBitmapContext (bitmapContext) and I would like to draw some rectangle part (rect) of it to the current CGContext (context).

Right now I do that way:

CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
CGContextClipToRect(context, rect);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
CGImageRelease(cgImage);

Is it optimal? What is the best way to do it?

like image 832
alexey Avatar asked Dec 14 '25 11:12

alexey


1 Answers

The alternative seems to be to create a sub-image, which I can only imagine to be less optimal.

like image 180
Chris Becke Avatar answered Dec 17 '25 02:12

Chris Becke