Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone screen capture for a view

On iphone, is it possible to "screen capture" an UIView and all its subview? If it is possible, how?

like image 353
huggie Avatar asked Aug 15 '10 14:08

huggie


People also ask

How do I screenshot a specific area on iPhone?

After pressing the Home and the Power button simultaneously, instead of taking a screenshot of your whole screen right away, the screen grays out allowing you to drag onto it to choose a specific portion which you want to take a screenshot of. After raising your finger, the screenshot will be saved to the Camera Roll.

How do I take a screenshot of an entire webpage?

Also, you can press Ctrl+Shift+P on Windows or Command+Shift+P on Mac. Type screenshot into the search box. Select Capture full-size screenshot.


1 Answers

I found this, but I haven't tried it myself.

Here you find the used -renderInContext.

I transformed the code above to a category on UIView. call it like this: [aView saveScreenshotToPhotosAlbum];

#import <QuartzCore/QuartzCore.h>

- (UIImage*)captureView {

    CGRect rect = [[UIScreen mainScreen] bounds];  
    UIGraphicsBeginImageContext(rect.size);     
    CGContextRef context = UIGraphicsGetCurrentContext();  
    [self.layer renderInContext:context];  
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    return img;
}



- (void)saveScreenshotToPhotosAlbum {
    UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);

}
like image 113
vikingosegundo Avatar answered Oct 04 '22 17:10

vikingosegundo