Rotate and/or Flip an Image from a File
This snippet gives the programmer the ability to Rotate and/or flip an Image from a file. The programmer can choose where to save the file, and it will overwrite the file if it exists.
VB.NET
''' <summary>
''' Rotates and/or flips an image from a file.
''' </summary>
''' <param name="imgPath">The path of the image you'd like to flip.</param>
''' <param name="savePath">The path of the flipped image you'd like to save to.</param>
''' <param name="rotFlipType">The RotateFlipType enum to flip or rotate the image.</param>
''' <param name="imgFormat">The format to save the file to.</param>
''' <remarks></remarks>
Public Sub rotFlipImageFromFile(ByRef imgPath As String, ByRef savePath As String, _
ByRef rotFlipType As RotateFlipType, ByRef imgFormat As System.Drawing.Imaging.ImageFormat)
Dim img As System.Drawing.Image
img = System.Drawing.Bitmap.FromFile(imgPath)
img.RotateFlip(rotFlipType)
' We delete the file if it exists so it doesn't fail.
If System.IO.File.Exists(savePath) Then System.IO.File.Delete(savePath)
img.Save(savePath, imgFormat)
End Sub
' Example usage of the snippet:
rotFlipImageFromFile("c:\lol.gif", "c:\lol.gif", RotateFlipType.RotateNoneFlipXY, _
Imaging.ImageFormat.Gif)
See Also
- </DIC> Submission - http://www.dreamincode.net/code/snippet1512.htm
page revision: 0, last edited: 16 Dec 2007 05:19