I have saved a bunch of CGContextRefs and I want to draw all of these out in the drawRect portion of my UIView. How can I do this?
A:
Here is one way:
- (void)drawRect:(CGRect)rect {
CGImageRef newImg = CGBitmapContextCreateImage(ctx1);
[[UIImage imageWithCGImage:newImg] drawInRect:rect];
CGImageRelease(newImg);
CGImageRef newImg = CGBitmapContextCreateImage(ctx2);
[[UIImage imageWithCGImage:newImg] drawInRect:rect];
CGImageRelease(newImg);
}
mahboudz
2009-09-08 05:23:37
Thanks. I have been reading about Graphics States. I'm just trying to save individual brush strokes so would saving and restoring graphics states be a faster way to do this?
RexOnRoids
2009-09-08 05:26:27
And how do I draw the resulting image in -drawRect?
RexOnRoids
2009-09-08 05:43:01
That's it. The resulting images are being drawn on top of each other into the rect provided to drawRect.
mahboudz
2009-09-08 18:16:30
You probably want to add blendmodes, or have the images draw next to each other instead of on top, but that's the gist of it. I'm not sure if this is faster than drawing individual brush strokes, but it does allow you to do some of the work at other times and then dump it all to the screen at drawRect time. There are also other paths to take from CGImageRef to drawing that won't have you turning the context back to an UIImage, which may speed things up.
mahboudz
2009-09-08 18:21:27