0

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?

YogevSitton
  • 10,068
  • 11
  • 62
  • 95

1 Answers1

0
- (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

Community
  • 1
  • 1
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
  • But this will capture the whole content. I only want what's currently visible + 100 pixels. Plus (and I'll add this to the description) I'm working with UITable. – YogevSitton Feb 25 '14 at 14:36