Search code examples
iphoneimagescreenshot

How to take screen shot in the app to a small frame by coding,iphone


i want to have a screen shot with in the app and then use that image in the next view. Is there is a way so we can take screen shot of a view in the app and then use that image.

Many thanks in advance

gagan joshi


Solution

  • Easy to do (assuming self is an UIViewController):

    #import < QuartzCore/QuartzCore.h >
    
    ...
    
    UIGraphicsBeginImageContext(self.view.bounds.size);
    
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    

    Now you have the screenshot in the variable screenshot and can put it into an UIImageView.