Quartz 2D: draw from a CGContext to another CGContext

Posted by alexey on Stack Overflow See other posts from Stack Overflow or by alexey
Published on 2010-06-15T09:29:23Z Indexed on 2010/06/15 9:32 UTC
Read the original article Hit count: 387

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?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about mac