Q:

How to get 2x image as screen shot?

I want to take screen shot of window and use that image as background view for new view controller. My problem is, that image is some what blur in retina display because the image should be 640X1136. But the following code returns image with size of only 320X568.
Note: If I use the apple's private API UIGetScreenImage() it returns the image in size 640X1136.
   -(UIImage*)getScreenShot:(CALayer*)layer 
    {
            UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0.0);
            [layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            return image;
    }

       [self getScreenShot:self.window.layer];

Is any way to get the screen shot image in size 640X1136 with out using apple's private API?

A:

-(UIImage*)getScreenShot:(CALayer*)layer
{
    CGFloat scale = 1.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
        scale = [[UIScreen mainScreen] scale];
    }
#endif
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width*scale, layer.frame.size.height*scale), NO, 0.0);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

