Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking a partial screenshot on the iPad

I'm trying to take a screenshot on save, but can only do full screen. Is there any way to take a partial screenshot?

Here is a sample. Say I just want to take a screenshot of the section highlighted in red. Thanks for the help.

http://img197.imageshack.us/img197/6499/sampleimagez.jpg

like image 949
user596472 Avatar asked Oct 10 '22 08:10

user596472


1 Answers

It looks like you want a screenshot of that web view there. If you want to get an image of a specific view and only that view (+ subviews), you can use the following code:

- (UIImage*)captureView:(UIView*)view
{ 
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    else
        UIGraphicsBeginImageContext(self.view.bounds.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [view.layer renderInContext:context];

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return img;
}

Just pass the web view to that function and it should work.

EDIT:

Assuming that was just an example image and you want a screenshot of an area that is not contained in its own view, go with Canada Dev's solution. Crop the image to the area that you want.

like image 168
Daniel G. Wilson Avatar answered Oct 13 '22 01:10

Daniel G. Wilson