Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnConvert_Click(object sender, EventArgs e)
- {
- if (txtInput.Text != "")
- {
- // Find files and put them into oldFiles
- DirSearch(txtInput.Text);
- // Setup the progress bar
- tsProgressBar.Maximum = oldFiles.Count;
- tsProgressBar.Step = 1;
- tsProgressBar.Visible = true;
- // Do the converting and update progress bar
- for (int i = 0; i < oldFiles.Count; i++)
- {
- SaveBmpAsPNG(oldFiles[i], newFiles[i]);
- tsProgressBar.PerformStep();
- tsStatusLabel.Text = "Converting " + oldFiles[i];
- }
- }
- // Clean up
- oldFiles.Clear();
- newFiles.Clear();
- tsStatusLabel.Text = "";
- tsProgressBar.Value = 0;
- tsProgressBar.Visible = false;
- }
- // Function to convert bitmaps to png files
- private void SaveBmpAsPNG(string oldFile, string newFile)
- {
- Bitmap bmp1 = new Bitmap(oldFile);
- bmp1.Save(@newFile, System.Drawing.Imaging.ImageFormat.Png);
- }
- // Folder recursion
- void DirSearch(string sDir)
- {
- // Create the folder structure in the output folder
- foreach (string dirPath in Directory.GetDirectories(txtInput.Text, "*",
- SearchOption.AllDirectories))
- {
- // Variable to hold the new folder structure
- string newFolder = dirPath.Replace(sDir, txtOutput.Text);
- // Check if the folder exists
- if (!Directory.Exists(newFolder))
- {
- // Create the new folder
- Directory.CreateDirectory(newFolder);
- }
- else
- {
- //MessageBox.Show("Folder already exists:\n" + newFolder, "Folder Exists!");
- }
- }
- foreach (string f in Directory.GetFiles(sDir, "*.bmp"))
- {
- // Process files in directory
- string newName = f.Substring(0, f.Length - 3) + "png";
- newName = newName.Substring(txtInput.TextLength, newName.Length - txtInput.TextLength);
- newName = txtOutput.Text + newName;
- oldFiles.Add(f);
- newFiles.Add(newName);
- //MessageBox.Show(f + "\n" + newName);
- }
- foreach (string d in Directory.GetDirectories(sDir))
- {
- DirSearch(d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement