I’m using CGContext in two steps: First create context, draw background image, draw with UIBezierPaths, then get the image & release the context. Secondly combine this image with another one like this:
UIGraphicsBeginImageContextWithOptions(self.anchorImage.size, NO, 1);
[self.anchorImage drawInRect:CGRectMake(0, 0, self.anchorImage.size.width, self.anchorImage.size.height)];
[tempImage drawInRect:CGRectMake(0, 0, self.anchorImage.size.width, self.anchorImage.size.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
This worked well in iOS4, however it’s very very slow in iOS5 (I’m testing on a 3GS). Am I doing something wrong? Or is there a more optimal way of doing this? Or is there a specific iOS5 way of doing it?
It’s not clear to me if you are just generating images, or drawing into a view. Anyway, to improve speed you could offload the generation of these images to a different dispatch queue, so your current thread (probably the main thread?) will not block.
Instead of
UIGraphics*I would useCGBitmapContextCreatein combination withCGBitmapContextCreateImage. When your final image has been generated update the image view (or do whatever else you want to do with the image).See the CGBitmapContext documentation for the full method signatures.