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{
    UIGraphicsBeginImageContext(targetView.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *fullScreenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    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);

HAPPY DEVELOPMENT;

free counters

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s