I donβt believe that. "DrawInContext" will clear the base buffer so you can draw it. However, if you abandon the drawInContext or drawRect methods, you can set your layer.contents to CGImage, which will be saved.
I personally do this for almost all of my routines. I overwrite - (void) setFrame:(CGRect)frame to check if the frame size has changed. If it has changed, I redraw the image using the usual normal drawing procedures, but in the context: UIGraphicsBeginImageContextWithOptions(size, _opaque, 0); . Then I can capture this image and set it to imageCache: cachedImage = UIGraphicsGetImageFromCurrentImageContext(); . Then I set layer.Contents to CGImage. I use this to help cache my drawings, especially on the new iPad, which is slow in many drawing procedures that the iPad 2 doesn't even blink.
Other advantages of this method: you can transfer cached images between views if you set up a separate shared cache. This can really help your memory if you manage the cache well. (Tip. I am using NSStringFromCGSize as a dictionary key for shared images). Alternatively, you can actually unscrew your drawing routines in another thread, and then set the contents of the layer when this is done. This will prevent blocking of the main drawing process (the current image can be stretched in this case until a new image is installed).
Aaron hayman
source share