Have a look at this answer.It also takes care of retina display.
Actually to explain the process,
- Choose a image context size (probably the layer size for which you need screen shot)
- Render the layer which you want to take screenshot in the created context
- Obtain the image from the context and you are done!