title: Xamarin UIImage rotation
body: <p>I try to rotate image and save it, when i save image as it, it works, but when i try to rotate the image, rotation works but image is blank.</p>
  
  <pre><code>  public UIImage RotateImage (UIImage originalImage, int rotationAngle)
          {
              UIImage rotatedImage = originalImage;
  
              if (rotationAngle &gt; 0) {
                  CGSize rotatedSize;
                  float angle = Convert.ToSingle ((Math.PI / 180) * rotationAngle);
  
                  using (UIView rotatedViewBox = new UIView (new CGRect (0, 0, originalImage.Size.Width, originalImage.Size.Height))) {
                      CGAffineTransform t = CGAffineTransform.MakeRotation (angle);
                      rotatedViewBox.Transform = t;
                      rotatedSize = rotatedViewBox.Frame.Size;
  
                      UIGraphics.BeginImageContext (rotatedSize);
                      CGContext context = UIGraphics.GetCurrentContext ();
  
                      context.TranslateCTM (rotatedSize.Width / 2, rotatedSize.Height / 2);
                      context.RotateCTM (angle);
                      context.ScaleCTM ((nfloat)1.0, -(nfloat)1.0);
  
                      context.DrawImage (new CGRect (-originalImage.Size.Width / 2, -originalImage.Size.Height / 2, originalImage.Size.Width, originalImage.Size.Height), originalImage.CGImage);
  
                      rotatedImage = UIGraphics.GetImageFromCurrentImageContext ();
  
                      UIGraphics.EndImageContext ();
                  }
  
              }
  
              return rotatedImage;
          }
  </code></pre>
  
  <p>Here is what i get :</p>
  
  <p><a href="http://i.stack.imgur.com/haeal.png" rel="nofollow">Rotated image</a></p>
  
  <p>And original image :</p>
  
  <p><a href="http://i.stack.imgur.com/vUugg.png" rel="nofollow">original image</a></p>
  
  <p>update : little code change</p>