Stand by...

 Print This Post

Convert BMP to JPG Command Line Tool (Free)

A small and free command line utility that converts a single .bmp file or a directory containing multiple .bmp files into jpg’s.

Requires .Net Framework 2.0 or later.

UPDATE! Sorry, the previous download File was corrupted. Please download this zip file now.

Download

  BMP2JPG.exe (8.0 KiB, 30,181 hits)

Help:
BMP2JPG :: Converts BMP to JPG (100% JPEG Quality only) :: Version 1.0

Converts BMP Files

Syntax :: BMP2JPG [Source Directory or File] [Destination Directory or File] [overwrite]

::
:: Examples
::
BMP2JPG "C:\Temp\My Bitmap.bmp" "C:\Temp\My JPEG File.jpg"
Converts a single File

BMP2JPG "C:\Temp\My BMP Folder" "C:\Temp\My JPEG Folder"
Converts all Files found in "C:\Temp\My BMP Folder" to "C:\Temp\My JPEG Folder"

BMP2JPG "C:\Temp\My BMP Folder" "C:\Temp\My JPEG Folder" overwrite
Converts all Files found in "C:\Temp\My BMP Folder" to "C:\Temp\My JPEG Folder"
Overwrites Existing Files

Author :: Tom Schindler, 2010 | http://www.microtom.net
Codename :: WIN32_ConvertBMP2JPG

Code:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
 
namespace BMP2JPG
{
    class Program
    {
 
        public static bool overwriteall = false;
 
        static void Main(string[] args)
        {
            CheckArguments(args);
 
            string source = args[0], destination = args[1];
 
            if (args.Length > 2)
            {
                if (args[2].ToLower() == "overwrite")
                    overwriteall = true;
            }
 
            if (Directory.Exists(source))
            {
                Console.WriteLine("Directory Found: {0}", source);
                foreach (string bmpfile in Directory.GetFiles(source, @"*.bmp"))
                {
                    ConvertFile(bmpfile, destination + @"\" + 
                        Path.GetFileNameWithoutExtension(source + @"\" + bmpfile).ToString() + ".jpg");
                }
                if (!Directory.Exists(destination))
                {
                    try
                    {
                        Directory.CreateDirectory(destination);
                    }
                    catch
                    {
                        Console.WriteLine("Unable to create destination Directory {0}", destination);
                        Environment.Exit(1);
                    }
                }
 
                /*
                foreach (string jpgfile in Directory.GetFiles(source, @"*.jpg"))
                {
                    ResizeFile(jpgfile, destination + @"\" +
                        Path.GetFileNameWithoutExtension(destination + @"\" + jpgfile).ToString() + "_Resize.jpg", 100, 100, 80);
                }
                */
 
            }
            else
            {
                    ConvertFile(source, destination);
            }
        }
 
        public static void ConvertFile(string source, string destination)
        {
            string input = "n";
 
            if (!File.Exists(source))
            {
                Console.WriteLine("Input File not found! {0}", source);
            }
 
            Console.WriteLine("Converting {0}", source);
 
            if (File.Exists(destination) & !overwriteall)
            {
                Console.WriteLine("The Destination File already exists! Overwrite? [Y]es, [N]o, [A]ll");
                input = Console.ReadLine().ToString().ToLower();
                if (input == "a")
                    overwriteall = true;
                else if (input != "y" & input != "n")
                {
                    Console.WriteLine("Invalid input! Possible Answers: y, n or a!");
                    return;
                }
            }
 
            if (input == "y" | overwriteall | !File.Exists(destination))
            {
                try
                {
                    using (Image img = Image.FromFile(source))
                    {
                        img.Save(destination, ImageFormat.Jpeg);
                    }
                    Console.WriteLine("Successfully converted {0} to {1}", source, destination);
                }
                catch 
                {
                    Console.WriteLine("Failed to convert {0}", source);
                }
            }
        }
 
        public static void ResizeFile(string source, string destination, int width, int height, long quality)
        {
            Bitmap b = new Bitmap(source);
            Image i = resizeImage(b, new Size(width, height));
            saveJpeg(destination, (Bitmap)i, quality);
        }
 
        private static Image resizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;
 
            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;
 
            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);
 
            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;
 
            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);
 
            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
 
            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();
 
            return (Image)b;
        }
 
        private static void saveJpeg(string path, Bitmap img, long encquality)
        {
 
            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, encquality);
 
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
 
            if (jpegCodec == null)
                return;
 
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
 
            img.Save(path, jpegCodec, encoderParams);
        }
 
        private static ImageCodecInfo GetEncoderInfo(String mimeType)
        {
            int j;
            ImageCodecInfo[] encoders;
            encoders = ImageCodecInfo.GetImageEncoders();
            for (j = 0; j < encoders.Length; ++j)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }
            return null;
        }
 
        public static void CheckArguments(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.WriteLine("  BMP2JPG   ::   Converts BMP to JPG (100% JPEG Quality only)    :: Version 1.0");
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.WriteLine("\n");
                Console.WriteLine("Started : " + DateTime.Now);
                Console.WriteLine("\n");
                Console.WriteLine("Converts BMP Files");
                Console.WriteLine("\n");
                Console.WriteLine("        Syntax :: BMP2JPG [Source Directory or File] [Destination Directory or File] [overwrite]");
                Console.WriteLine("\n");
                Console.WriteLine("::");
                Console.WriteLine(":: Examples");
                Console.WriteLine("::");
                Console.WriteLine("     BMP2JPG \"C:\\Temp\\My Bitmap.bmp\" \"C:\\Temp\\My JPEG File.jpg\"");
                Console.WriteLine("              Converts a single File");
                Console.WriteLine("\n");
                Console.WriteLine("     BMP2JPG \"C:\\Temp\\My BMP Folder\" \"C:\\Temp\\My JPEG Folder\"");
                Console.WriteLine("              Converts all Files found in \"C:\\Temp\\My BMP Folder\" to \"C:\\Temp\\My JPEG Folder\"");
                Console.WriteLine("\n");
                Console.WriteLine("     BMP2JPG \"C:\\Temp\\My BMP Folder\" \"C:\\Temp\\My JPEG Folder\" overwrite");
                Console.WriteLine("              Converts all Files found in \"C:\\Temp\\My BMP Folder\" to \"C:\\Temp\\My JPEG Folder\"");
                Console.WriteLine("              Overwrites Existing Files");
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.WriteLine("        Author :: Tom Schindler, 2010 | http://www.microtom.net");
                Console.WriteLine("      Codename :: WIN32_ConvertBMP2JPG");
                Environment.Exit(0);
            }
        }
    }
}

This post was written by microtom and has 44,209 views in total

(20 votes, average: 4.40 out of 5)
Loading ... Loading ...

33 Comment(s). Add a comment or Trackback

  • microtom  15:20 Jul 15, 2014 

    Hi Clark, can you post the BatchFile you have written?

  • Clarkdale44  12:41 Jul 15, 2014 

    Every time i click on the bat file i want the output filename to be random, even if the input filename is the same. How to do that?

  • microtom  14:56 Apr 01, 2014 

    Hi Ali

    You can copy the BMP2JPG.exe into your Windows or Windows\System32 directory and simply go to start, run and type “CMD”.

    You can run this command to convert all BMP’s found in a Folder and its Sub-directories to C:\AllMyPictures:
    for /f %i in (‘dir C:\PathToMyBMPPictures /A:D /S /B’) do bmp2jpg.exe “%I” C:\MyNewJPEGPictures

    If you DON’t want the Subdirectories included run this command (Replace with your Paths):
    BMP2JPG.exe “C:\PathToMyBMPPictures” “C:\MyNewJPEGPictures”

    Drag and Drop is not supported. This was intended to be a command line utility only.

    Hope this helps

    Tom

  • Ali Gönüllü  14:33 Apr 01, 2014 

    Hi,

    In command line difficult to write folder adresses.
    Because I have too much folder and bmp files in this folders.
    I put bmp2jpg.exe and cmd.exe in a folder. First I launched cmd.exe.
    Now, I m in the folder in command line.
    When I wrote bmp2jpg or bmp2jpg *.* , I expect that convert all bmp files to jpg in same folder.

    Is is possible to do this?

    Or When I select for example 15 bmp files and drag to bmp2jpg.exe (whitout open a command line)they can be converted in the same folder.

  • microtom  09:08 Feb 20, 2014 

    Hi MKW

    Do you receive an error message? If so, can you post it here?

    Greetings

    Tom

  • mkw007  08:16 Feb 20, 2014 

    It’s great!
    But,when it converts a Bmp over the size 10000*10000 and over 300M by a PC with 3G Memory,It fails. Can you improve it to handle big BMP file?

  • microtom  19:38 Aug 13, 2013 

    Hello Joel

    Sure, no Problem. As long as you do not work for a Company called Fossil or intend to redistribute the code I am ok with that ;).

    Greetings, Tom

  • YAMI Joel  19:34 Aug 13, 2013 

    Congratulations for the good work. I wonder if I could use this programm in my company? This program is free?

  • Damu  03:45 Dec 13, 2012 

    Very cool….much helpful for bulk conversions…

  • microtom  23:34 Nov 12, 2012 

    Hello Gene

    Thanks for the comment. unfortunately no, but you can actually easily use a simple for-loop in a command prompt to do so, for example:

    for /f %i in (‘dir C:\ /A:D /S /B’) do bmp2jpg.exe “%i” C:\AllMyPictures

    This would parse all subfolders of C:\ and convert all found BMP files to C:\AllMyPictures
    Let me know if you need any help.

    Greetings, Tom

  • Gene  20:48 Nov 12, 2012 

    I like this app you developed ! ( BMP2JPG ) Very usefull.

    One question If I may. Can it be used Globally over a drive or a folder and all its sub directories. If so would you offer the Syntax
    of the command line ?

    Thanks,
    Gene

  • microtom  12:04 Sep 28, 2012 

    Good old times! :’)

  • David  01:24 Sep 28, 2012 

    Works Great!!!
    kinda give me some tears…. makes me miss DOS and CP/M

  • alexshirv  21:03 Sep 23, 2012 

    great software, huge thanks

  • marcio  15:10 Aug 30, 2012 

    excelent…

    very simple to use and it works….

  • freddan  15:44 Jul 19, 2012 

    omg!! I f*cking love this!! Perfect for my Fallout 3, Fallout: New Vegas and The Elder Scrolls series

    just put the .exe in the game dir and make a .bat like this:

    @echo off
    bmp2jpg . “%USERPROFILE%\Pictures\The Elder Scrolls V Skyrim Screenshots\”
    del *.bmp
    pause

    works flawlessly and 100% automatic! Love this!!

  • ASC  16:57 Jul 15, 2012 

    Hello Tom,

    many thanks. Excelent, thanks alot

    Alex

  • microtom  15:57 Jul 15, 2012 

    Hello ASC,
    Thanks for your comment, you can freely use the tool within your Company as long as you are not reselling it.

    Greetings, Tom

  • ASC  15:09 Jul 15, 2012 

    Hi Tom,

    I want to use this excellent tool in a script in our business for providing info on log on screen at Windows 7.
    How is this tool licensed?

    Best regards

  • microtom  08:12 May 30, 2012 

    Hello Robert

    Can you send me the name and description (maybe URL?) of your application? I guess you’re working for a small company, correct?

    Tom

  • Robert  18:06 May 29, 2012 

    Tom,
    May I redistribute your bjp2jpg program in my own commercial application
    Thanks,
    Robert

  • Adam Hauerwas  18:48 Mar 20, 2012 

    Tom, thanks for posting the code! I need to do BMP -> JPG conversion for the logged-out screen in Win7 (refer to posts at http://forum.sysinternals.com/topic20426_post117788.html for more info). I’d like to redistribute your code if at all possible — please contact me at?

  • Tr  09:40 Mar 08, 2012 

    been a very useful script. Following its conversion to JPG BMP files can be added delete feature?

  • microtom  12:14 Dec 12, 2011 

    Sure man, I have updated the post above

  • Kashif Iqbal  12:06 Dec 12, 2011 

    Can i have the source code for this? I want it to be a part of my an application.

    Kashif

  • kumar  04:42 Jul 24, 2011 

    thanks sir,., its working.

  • Ulf  14:02 Apr 05, 2011 

    Thanks a lot, m8 :-)

  • Brian  02:12 Sep 30, 2010 

    I get this…
    You don’t have permission to access /wp-content/files/BMP2JPG.exe on this server.

  • oliver marshall  10:01 Aug 18, 2010 

    I get a 403 error when trying the download link

  • microtom  09:36 Jul 21, 2010 

    It’s incredible that some people are bored enough to start attacking by trying to use massive hit counts on download content. :) I uploaded the original exe file again

  • Simon  16:37 Jul 20, 2010 

    The file is still empty.
    Is the link ( http://www.microtom.net/?dl_id=3 ) correct?

  • microtom  16:31 May 18, 2010 

    Damn, again! Don’t know whats wrong with that download manager :) I uploaded it again, please give it another try.

  • Alex  11:32 May 18, 2010 

    The Zip file is empty!

Leave a comment ↓

Welcome back, (change)

submitting...

1Pingbacks & Trackbacks