简体   繁体   中英

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

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.

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