Getting a Screencapture of UIView

Posted on Updated on

Some times you have to capture a portion of you iPhone application programmatically;
The quickest way is to pass the target view to following method and get its screenshot as an UIImage;

-(UIImage*)captureFullScreen:(UIView*) targetView{
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *fullScreenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil);
    return fullScreenshot;

– To capture whole screen, you don’t need to pass any parameter to this method, instead use self.view.frame in first line;

– To save the captured image into your device’s album, use  UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil);


free counters


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s