Converts a bitmap file to another format which you specify. The new file is saved in the same folder with the same file name, with the appropriate extension (e.g., C:\a.bmp is saved as C:\aa.gif)
Declare this 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)
|
| Author: Vasudevan Deepak Kumar 14 May 2008 | Member Level: Diamond Points : 2 |
A few days back I have shared a similar topic on System.Drawing.Imaging API here:
http://www.dotnetspider.com/resources/3020-Quick-Effective-Tips-Image-API-Input-Validat.aspx
|