Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save full screenshot including bars

I am having problems with the following code only takes a photo of my UITableView only and not the entire screen with the navigation and tab bars...

I would like the full screen capturing including navigation and tab bars. Any help greatly appreciated.

- (UIImage*)captureView:(UIView *)view
{
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
like image 225
Steve Avatar asked Apr 26 '13 17:04

Steve


2 Answers

The following code worked for me a couple of months ago:

CALayer *layer = [[UIApplication sharedApplication] keyWindow].layer;
CGFloat scale = [UIScreen mainScreen].scale;
UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, scale);

[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
like image 188
kovpas Avatar answered Oct 20 '22 16:10

kovpas


Swift 3.0 Version if any one needs

func getScreenShot() -> UIImage {

        let layer : CALayer = (UIApplication.shared.keyWindow?.layer)!
        let scale : CGFloat = UIScreen.main.scale
        UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale)
        layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
like image 35
iOSer Avatar answered Oct 20 '22 16:10

iOSer