To render into an offscreen context and save it as a CGImageRef:
void *bitmapData = calloc(height, bytesPerLine);
CGContextRef offscreen = CGBitmapContextCreate(..., bitmapData, ...)
// draw stuff into offscreen
CGImageRef image = CGBitmapContextCreateImage(offscreen);
CFRelease(offscreen);
free(bitmapData);
To draw it on the screen:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, rect, image);
}
You could also just save the image in the view's layer's contents property (view.layer.contents = image
), or use a UIImageView.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…