0

I have a UIScrollView that has content that needs to be emailed. The screenshot only captures the visible areas on the screen. The scroll view size is 768 x 2000. The method I am using at the moment is the following;

- (IBAction) Email
{
    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();

    NSData * imageData = UIImageJPEGRepresentation(image, 0.95);


    if ([MFMailComposeViewController canSendMail]) {

        MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
        mc.mailComposeDelegate = self;

        [mc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"Attachment.jpeg"];
        [self presentModalViewController:mc animated:YES];

    }
}

Thanks for the replies. I realised I only had the scrollview as an outlet and not a property. Changed the code to the following and fixed the issue;

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
knowles3226
  • 65
  • 1
  • 7
  • So, what is the problem? What part of your function is not working? – Rudi Angela Jan 25 '15 at 22:01
  • The above code only takes a screen shot of the visible view and not the whole scroll view. I assume the image context is incorrect to capture the whole scroll view – knowles3226 Jan 26 '15 at 08:33
  • What about making a PDF of the view and emailing it? Look [here](http://stackoverflow.com/questions/5443166/how-to-convert-uiview-to-pdf-within-ios) for a how to. – Rob Sanders Jan 26 '15 at 09:51
  • Thanks for the replies. I realised I only had the scrollview as an outlet and not as a property as well. The resolution is quite poor though. Any ideas on how to improve image quality? – knowles3226 Jan 26 '15 at 21:07
  • 1
    Try using `UIGraphicsBeginImageContextWithOptions(_scrollView.contentSize,YES,0.0);` instead of `UIGraphicsBeginImageContext(_scrollView.contentSize);` to make sure that you generate the result in "retina" resolution. – Cihan Tek Jan 26 '15 at 21:26

0 Answers0