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
Post a Comment