Capturing UIView contents to image

For stunning animations and effects, sometimes it is useful to capture the contents of the view into an image before starting the animation, or simply just save the content to an image file.
There is a quite easy way to do this on icodeblog.