Q:

Add background to screenshot

I would like to add a background to my taken screenshot, but something went wrong. The return of the image is only the background without the screenshot. Here´s my code, can you fix it please?
- (UIImage *)screenshot
{
UIImage *backgroundImage = [UIImage imageNamed:@"iphoneframe.png"];
UIGraphicsBeginImageContext(backgroundImage.size);
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIGraphicsEndImageContext();

[screenshot drawInRect:CGRectMake(backgroundImage.size.width - screenshot.size.width, backgroundImage.size.height - screenshot.size.height, screenshot.size.width, screenshot.size.height)];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

return image;
}

Background/Frame I want to put around the screenshot: http://oi45.tinypic.com/2qvv2tv.jpg 
Prototype Image, which should be returned: http://i.stack.imgur.com/hg1nW.png
Update: The problem was solved with the tips from @panayot-panayotov and @jrturton - the idea was to remove second UIGraphicsBeginImageContext & place UIGraphicsEndImage Context(); above return Image;, but now the picture is like this: pbs.twimg.com/media/BnlkN9wIAAEG-ue.jpg:large - how can we fix this? Any ideas?

A:

You're creating two image contexts, and drawing a different image in each one. Don't create the second context (UIGraphicsBeginImageContext...), and move the end context call until after you've taken out the final image, and you should be fine. 
It's also worth noting that you should use the newer 'with options' version when making an image context - this will allow you to draw properly on retina devices. 

