iphone - Save UIView's representation to file -


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

My solution is,

  UIGraphicsBeginImageContext (someView.frame.size); [SomeView drawRect: someView.frame]; UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); NSString * path ++ "@ sample.png"; NSDTA * imageData = [NSDATA DataWithData: UIMJPNGREPNation (image)]; [ImageData writeToFile: Prepare the path atomically: yes];  

But it seems difficult, and I think it should be a more effective way to do this.

You can also use the layer like this:

  UIGraphicsBeginImageContext (someView.bounds.size); [SomeView.layer renderInContext: UIGraphicsGetCurrentContext ()]; UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext ();  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -