Save UIView's representation to file.

Posted by fish potato on Stack Overflow See other posts from Stack Overflow or by fish potato
Published on 2010-06-16T08:18:43Z Indexed on 2010/06/16 8:22 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

What is the easiest way to save UIView's representation to file?

My solution is,

 UIGraphicsBeginImageContext(someView.frame.size);
 [someView drawRect:someView.frame];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 NSString* pathToCreate = @"sample.png";

 NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
 [imageData writeToFile:pathToCreate atomically:YES];

but it seems tricky, and I think there must be more efficient way to do this.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about image