2

I have a scrollview, frame size is 480x265 and content size is 1800x600.

I have a lot of UIView added as a subview to this scrollview.

May I know how should I be able to convert this scrollview to an image?

Many thanks for any comments/help in advance!

user229044
  • 222,134
  • 40
  • 319
  • 330
Erwin
  • 21
  • 3
  • This is a duplicate of http://stackoverflow.com/questions/3539717/getting-a-screenshot-of-a-uiscrollview-including-offscreen-parts – Rambatino May 19 '15 at 15:20

2 Answers2

3
- (void)submitClicked
{
     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()];     
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

     scrollView.contentOffset = savedContentOffset;
     scrollView.frame = savedFrame;

     UIGraphicsEndImageContext();
}  
Omar
  • 105
  • 4
Areeba Khan
  • 71
  • 1
  • 10
0

Seems like you want to save the content of your scroll view to image.

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"myImage.png" atomically:YES];
Vlad
  • 5,453
  • 3
  • 35
  • 59
Vineet Singh
  • 4,793
  • 1
  • 29
  • 39
  • This will only capture the visible portions of the scrollview and it will clip the rest of the contents that are not visible – iwasrobbed May 30 '13 at 03:11