How to reset the context to the original rectangle after clipping it for drawing?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-04-06T15:13:05Z Indexed on 2010/04/06 15:23 UTC
Read the original article Hit count: 198

Filed under:

I try to draw a sequence of pattern images (different repeated patterns in one view).

So what I did is this, in a loop:

CGContextRef context = UIGraphicsGetCurrentContext();

// clip to the drawing rectangle to draw the pattern for this portion of the view
CGContextClipToRect(context, drawingRect);

// the first call here works fine... but for the next nothing will be drawn
CGContextDrawTiledImage(context, CGRectMake(0, 0, 2, 31), [img CGImage]);

I think that after I've clipped the context to draw the pattern in the specific rectangle, I cut out a snippet from the big canvas and the next time, my canvas is gone. can't cut out another snippet. So I must reset that clipping somehow in order to be able to draw another pattern again somewhere else?

Edit: In the documentation I found this:

CGContextClip: "... Therefore, to re-enlarge the paintable area by restoring the clipping path to a prior state, you must save the graphics state before you clip and restore the graphics state after you’ve completed any clipped drawing. ..."

Well then, how to store the graphics state before clipping and how to restore it?

© Stack Overflow or respective owner

Related posts about iphone