Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate an image X degrees C# wpf [closed]

This has been bothering me for ages, I just want a simple method that rotates an image X degrees. (this is for a turret defense game in which the turrets need to shoot a certain direction)

I want something like this:

public Image getRotatedImage(Image img, float angle)
{
     //Code here to rotate the image
     return img
}

All of this in c# wpf ofcourse and dynamically.. Hope you guys can help me out here :D


1 Answers

Don't use code to change your image. Let WPF rotate it for you using a RotateTransform.

<Image ...>
    <Image.RenderTransform>
        <RotateTransform Angle="45" />
    </Image.RenderTransform>
</Image >

Or apply a RotateTransform to your image in code:

RotateTransform rotateTransform = new RotateTransform(45);
img.RenderTransform = rotateTransform;
like image 84
Nathan A Avatar answered Sep 09 '25 21:09

Nathan A