Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Convert JPG to PNG Format (Bulk or Single)

0.00/5 (No votes)
4 Dec 2013 1  
This tip will help in understanding the directory and file dialog box, the progressbar control, and image conversion.

Introduction

This tip covers many things simultaneously. This tip will help in understanding the directory and file dialog box, and also the progressbar control and image conversion.

Using the Code

I have used very simple and easy to understand code. I am saving PNG images at the same location from where the application is getting JPG images. This can be changed as per your requirements.

//Get all JPG files from the location provided.
private void ReadJPGFiles(string path)
{
    var files = Directory.EnumerateFiles(path).Where(p => 
    Path.GetExtension(p).ToUpper() == ".JPG" || 
    Path.GetExtension(p).ToUpper() == ".JPEG")
                                            .Select(p => Path.GetFullPath(p));

    progressBar1.Maximum = files.Count();
    progressBar1.Value = 0;
    foreach (string s in files)
    {
        ConvertToPng(s, Path.GetFileNameWithoutExtension(s));
        progressBar1.Value += 1;
    }

}
//Convert JPG image to PNG
private void ConvertToPng(string path,string fileName)
{
    Image bmpImageToConvert = Image.FromFile(path);
    bmpImageToConvert.Save(FolderPath + "\\" + 
    fileName.Trim() + ".png", ImageFormat.Png);
}
...

History

  • 3rd December, 2013: Initial version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here