Library code snippets
Crafty Conversion Between Graphic Formats
Need a function to convert between bitmap, GIF, EMF, JPEG, PNG, WMF, and ICO image formats, among others? Don’t buy a third-party control: this conversion is exactly what my next crafty little snippet does. And all in a mere dozen lines of code.
Just call ConvertImage, passing in the filename of your current file, the desired
format of your new file (using the enumeration), and your new filename. And
that’s
it:
Public Sub ConvertImage(ByVal Filename As String, _
ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
ByVal NewFilename As String)
' Takes a filename and saves the file in a new format
Try
Dim imgFile As System.Drawing.Image = _
System.Drawing.Image.FromFile(Filename)
imgFile.Save(NewFilename, DesiredFormat)
Catch ex As Exception
Throw ex
End Try
End Sub
Here’s an example of using this to convert a GIF image into a Windows bitmap:
ConvertImage("c:\img1.gif",
System.Drawing.Imaging.ImageFormat.Bmp, "c:\img2.bmp")
Related articles
Related discussion
-
integrating barcode reader in vb 2005
by onew29 (0 replies)
-
MSSQL Query in VB.Net Fails
by 7upsk (1 replies)
-
bar graphs in visual basic.net
by bhabybash (1 replies)
-
How to write the category attribut in a class dynamically
by converter2009 (1 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
Related podcasts
-
xpert to Expert: Inside Concurrent Basic (CB)
"Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...
I've tried this code, and although it can convert a gif to a bitmap, it leaves the file with indexed colours. This means you can't do functions such as bmp.setPixel().
Unfortunately this doesn't work when converting an image to ICO or WMF there is a KB 316563 which statest that the ICO and WMF formats are readonly for conversion purposes. If you attempt to use them for write they default to PNG.
This thread is for discussions of Crafty Conversion Between Graphic Formats.