Last active
          December 11, 2015 20:39 
        
      - 
      
- 
        Save prashantvc/4657263 to your computer and use it in GitHub Desktop. 
    Extension method to convert UIView to UIImage
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public static class Extensions | |
| { | |
| public static UIImage ToImage (this UIView view) | |
| { | |
| RectangleF canvasRect = view.Bounds; | |
| UIGraphics.BeginImageContextWithOptions (canvasRect.Size, false, 0.0f); | |
| CGContext ctx = UIGraphics.GetCurrentContext (); | |
| ctx.FillRect (canvasRect); | |
| view.Layer.RenderInContext (ctx); | |
| UIImage newImage = UIGraphics.GetImageFromCurrentImageContext (); | |
| UIGraphics.EndImageContext (); | |
| NSData imgData = newImage.AsPNG (); | |
| return UIImage.LoadFromData (imgData); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment