To rotate a image in C# and VB.NET you can use the following snippet.
Sample C#
public enum RotateMode { Ninetee = 0, OneHundretEighty = 1, TwoHundredSeventy = 2, } public static Image RotateImage(Image myImage, RotateMode myRotatemode) { var ret = myImage; switch (myRotatemode) { case RotateMode.Ninetee: ret.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case RotateMode.OneHundretEighty: ret.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case RotateMode.TwoHundredSeventy: ret.RotateFlip(RotateFlipType.Rotate270FlipNone); break; } return ret; }
Sample VB.NET
Public Enum RotateMode Ninetee = 0 OneHundretEighty = 1 TwoHundredSeventy = 2 End Enum Public Shared Function RotateImage(myImage As Image, myRotatemode As RotateMode) As Image Dim ret = myImage Select Case myRotatemode Case RotateMode.Ninetee ret.RotateFlip(RotateFlipType.Rotate90FlipNone) Exit Select Case RotateMode.OneHundretEighty ret.RotateFlip(RotateFlipType.Rotate180FlipNone) Exit Select Case RotateMode.TwoHundredSeventy ret.RotateFlip(RotateFlipType.Rotate270FlipNone) Exit Select End Select Return ret End Function
RT @CodeSnippetsNET: How to rotate a image in .NET http://t.co/I7abpIi6Ij #dotnet #csharp #vb #programming #code #coding #dev