How to Convert BMP to JPG in VB
Visual Basic (VB) provides programmers with internal functions, allowing them to convert an image format to another. One such function is converting a bitmap image (BMP) to the standard JPG format. JPG is a smaller file, so large BMP files are typically converted to JPG to improve website or desktop application performance. This can be accomplished using the \"Save\" function included in Visual Basic's image library of functions.
Instructions
-
-
1
Include the image library that comes with Visual Basic. Include these lines of code at the top of your VB project:<br />Imports System.IO.Path<br />Imports System.Drawing.Imaging
-
2
Load your BMP file. A bitmap is created and loaded using the following code:<br />Dim bp As New Bitmap(\"c:\\theBMPfile.bmp\")<br />The code above loads a new bitmap file (named \"theBMPfile.bmp\") into the image object for Visual Basic.
-
-
3
Set Visual Basic with a new file name. The new file name is saved in a string object. To create a new file name, initialize a variable and assign the file name to the variable. The following code is how to assign a file name to a variable:<br />Dim filename As String<br />filename = \"NewBMPFile.JPG\"
-
4
Convert the BMP to a JPG. Visual Basic includes a \"Save\" function that is similar to the \"Save As\" function in a computer program. This function does the actual conversion, and it creates a JPG file on your computer. Add the following code to your VB program:<br />objBmp.Save(filename, ImageFormat.Jpeg)
-
1
Tips & Warnings
You can convert a BMP file to other formats using this process. For instance, change the \"ImageFormat.Jpeg\" to \"ImageFormat.Gif\" to save it as a GIF file.
References
- Photo Credit Jupiterimages/Photos.com/Getty Images