17-10-12, 05:04 PM
كاتب الموضوع : AhmedEssawy
في القسم العام :كود :
Imports System.IO.Path
Imports System.Drawing.Imaging
كود :
Public Function ConvertBMP(ByVal BMPFullPath As String, _
ByVal imgFormat As ImageFormat) As Boolean
Dim bAns As Boolean
Dim sNewFile As String
Try
'bitmap class in system.drawing.imaging
Dim objBmp As New Bitmap(BMPFullPath)
'below 2 functions in system.io.path
sNewFile = GetDirectoryName(BMPFullPath)
sNewFile &= GetFileNameWithoutExtension(BMPFullPath)
sNewFile &= "." & imgFormat.ToString
objBmp.Save(sNewFile, imgFormat)
bAns = True 'return true on success
Catch
bAns = False 'return false on error
End Try
Return bAns
End Function
'USAGE
'ConvertBMP("C:\test.bmp", ImageFormat.Jpeg)
'ConvertBMP("C:\test.bmp", ImageFormat.Emf)
'ConvertBMP("C:\test.bmp", ImageFormat.Exif)
'ConvertBMP("C:\test.bmp", ImageFormat.Gif)
'ConvertBMP("C:\test.bmp", ImageFormat.Icon)
'ConvertBMP("C:\test.bmp", ImageFormat.MemoryBmp)
'ConvertBMP("C:\test.bmp", ImageFormat.Png)
'ConvertBMP("C:\test.bmp", ImageFormat.Tiff)
'ConvertBMP("C:\test.bmp", ImageFormat.Wmf)