I am performing some CG drawing operations into a CGContext that I created for an MKMapOverlayView. After drawing into my context, I create an image and paste it into the context that MapKit provided.
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
CGColorSpaceRef colorRef = CGColorSpaceCreateDeviceRGB();
CGContextRef myContext = CGBitmapContextCreate(NULL, kTileSize, kTileSize, 8, 0, colorRef, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorRef);
CGContextSetAllowsAntialiasing(myContext, TRUE);
//...cut out drawing operations...
CGImageRef image = CGBitmapContextCreateImage(myContext);
CGContextDrawImage(context, [self rectForMapRect:mapRect], image);
CGImageRelease(image);
CGContextRelease(myContext);
}
Is there a way to simply copy myContext
into context
without having to create an image?
I realize that some of you will say "why not just draw directly into the context that MapKit provides". Unfortunately, we're experiencing a drawing glitch when rendering into context
directly. Apple is currently investigating this issue for us, but in the meantime we need to get a workaround in place. This workaround I presented above is my "best" shot, but it is a bit on the slow side.
P.S. I have started a bounty since I'm looking for an answer here too. Specifically I'm targeting OS X. So the answer should work there. The OP was looking for an answer on iOS.