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.
public UIImage RotateImage (UIImage originalImage, int rotationAngle)
{
UIImage rotatedImage = originalImage;
if (rotationAngle > 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;
}
Here is what i get :
And original image :
update : little code change