Private Sub CorrectPictureExtention(ByVal PictureFile As String)
Dim FileData As FileInfo = My.Computer.FileSystem.GetFileInfo(PictureFile)
If FileData.Exists = True Then
Dim PictureBitmap As Bitmap = Nothing
Try
PictureBitmap = Bitmap.FromFile(PictureFile)
Catch
End Try
If PictureBitmap IsNot Nothing Then
Dim GuidDictionary As New Dictionary(Of String, String)
GuidDictionary.Add("b96b3cab-0728-11d3-9d7b-0000f81ef32e", ".Bmp")
GuidDictionary.Add("b96b3cac-0728-11d3-9d7b-0000f81ef32e", ".Emf")
GuidDictionary.Add("b96b3cb0-0728-11d3-9d7b-0000f81ef32e", ".Gif")
GuidDictionary.Add("b96b3cb5-0728-11d3-9d7b-0000f81ef32e", ".Ico")
GuidDictionary.Add("b96b3cae-0728-11d3-9d7b-0000f81ef32e", ".Jpg")
GuidDictionary.Add("b96b3caf-0728-11d3-9d7b-0000f81ef32e", ".Png")
GuidDictionary.Add("b96b3cb1-0728-11d3-9d7b-0000f81ef32e", ".Tif")
GuidDictionary.Add("b96b3cad-0728-11d3-9d7b-0000f81ef32e", ".Wmf")
Dim ImageType As String = ""
GuidDictionary.TryGetValue(PictureBitmap.RawFormat.Guid.ToString, ImageType)
PictureBitmap.Dispose()
If ImageType <> "" Then
If FileData.Extension <> "" Then
If FileData.Extension <> ImageType Then
My.Computer.FileSystem.RenameFile(FileData.FullName, FileData.Name.Replace(FileData.Extension, "") & ImageType)
Else
My.Computer.FileSystem.RenameFile(FileData.FullName, FileData.Name & ImageType)
End If
End If
End If
End If
End If
End Sub
Tips and tricks for .NET using ASP and VB code.
Correct picture file extension
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment