I am working with Xamarin.iOS and now I want to rotate the image 90 degrees in ImageView when I click button.I found a similar issue.But it wrote in OC and Swift.How to implement it in C#?I couldn't find method such as CGAffineTransformMakeRotation
.
Asked
Active
Viewed 587 times
0

MonkeySteve
- 99
- 7
2 Answers
2
in Xamarin it's CGAffineTransform.MakeRotation
using CoreGraphics;
// 1.5708 is 90 degrees in Radians
myImageView.Transform = CGAffineTransform.MakeRotation(1.5708f);

Jason
- 86,222
- 15
- 131
- 146
-
Thanks! Jason. But I just want to rotation the image and reset the image of imageview. – MonkeySteve Nov 16 '18 at 00:51
2
Try to refer the following code
public UIImage RotateImage(UIImage image, float degree)
{
float Radians = degree * (float)Math.PI / 180;
UIView view = new UIView(frame: new CGRect(0, 0, image.Size.Width, image.Size.Height));
CGAffineTransform t = CGAffineTransform.MakeRotation(Radians);
view.Transform = t;
CGSize size = view.Frame.Size;
UIGraphics.BeginImageContext(size);
CGContext context = UIGraphics.GetCurrentContext();
context.TranslateCTM(size.Width/2, size.Height/2);
context.RotateCTM(Radians);
context.ScaleCTM(1, -1);
context.DrawImage(new CGRect(-image.Size.Width/2, -image.Size.Height/2, image.Size.Width, image.Size.Height), image.CGImage);
UIImage imageCopy = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return imageCopy;
}
Then you can reset the image of UIImageView. Here is a similar issue you can refer .

Lucas Zhang
- 18,630
- 3
- 12
- 22
-
It works ! Thank you lucas. You and your colleagues saved me from time to time. – MonkeySteve Nov 16 '18 at 01:33
-
-
Not very happy .I've been working 30 hours overtime without sleep. – MonkeySteve Nov 16 '18 at 01:36