简体   繁体   中英

Screen Capture beyond the bounds of the screen

I'm using UIGraphicsBeginImageContextWithOptions in order to get a screen grab of the currently displayed screen (UITable).

Here's my code:

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Then I'm using image object as the screen grab of my screen.

My problem is that I want the screen grab to include extra 100 pixels of currently undisplayed data (it will be displayed if I scroll down).

How can I do that?

- (IBAction) renderScrollViewToImage
 {
   UIImage* image = nil;

   UIGraphicsBeginImageContext(_scrollView.contentSize);
  {
    CGPoint savedContentOffset = _scrollView.contentOffset;
    CGRect savedFrame = _scrollView.frame;

    _scrollView.contentOffset = CGPointZero;
    _scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);

    [_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];     
    image = UIGraphicsGetImageFromCurrentImageContext();

    _scrollView.contentOffset = savedContentOffset;
    _scrollView.frame = savedFrame;
   }
  UIGraphicsEndImageContext();

if (image != nil) {
    [UIImagePNGRepresentation(image) writeToFile: @"/tmp/test.png" atomically: YES];
    system("open /tmp/test.png");
  }
}

Reference link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM