Reusable Snippets

Capture UIView

A little snip for creating an image from an UIView. Much like a snapshot from an view or rect. and exports new image to the photo album.

 

 

#import <QuartzCore/QuartzCore.h>

 

- (UIImage*)captureView:(UIView *)view {

CGRect rect = [[UIScreen mainScreen] bounds];  

UIGraphicsBeginImageContext(rect.size);  

CGContextRef context = UIGraphicsGetCurrentContext();  

[view.layer renderInContext:context];  

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  

UIGraphicsEndImageContext();  

return img;

}

 

- (void)saveScreenshotToPhotosAlbum:(UIView *)view {

UIImageWriteToSavedPhotosAlbum([self captureView:view], nil, nil, nil);

}

 

Filed under  //   Capture   Core Graphics   Images   Objective- C   iPhone  
Posted May 5, 2010