1

This is my code..

extern CGImageRef UIGetScreenImage();
CGRect frame = CGRectMake(0, 0, 320, 548);
CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, frame);            
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];    
CGImageRelease(cgoriginal);                
CGImageRelease(cgimg);

It takes screen shot but not full screen. I know this problem in CGRect frame. But I don't know, how to fix that..

Seeker
  • 644
  • 1
  • 8
  • 18

1 Answers1

0

Pay attention that UIGetScreenImage is a private API, so it will be rejected. If you want to do something similar you can try to use -renderInContext on the window layer or -drawViewHierchyInRect(only ios7). This method should be used as a category on UIView:

- (UIImage *) imageByRenderingViewOpaque:(BOOL) yesOrNO {
        UIGraphicsBeginImageContextWithOptions(self.bounds.size, yesOrNO, 0);

    if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
        [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
    }
    else {
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    }
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resultingImage;
}

You have also this method that you can call on UIScree instance - (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates, but that will return only a view not an image.

Andrea
  • 26,120
  • 10
  • 85
  • 131