private void ImageFilmGeneration(string tempPath) { try { string input = tempPath + "\\*." + SelectedFileExtension.ToString(); string output = tempPath + "\\imagefilm." + SelectedFileExtension.ToString(); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C convert -append \"" + input + "\" \"" + output + "\""; process.StartInfo = startInfo; process.Start(); process.WaitForExit(); process.Close(); } catch (Exception ex) { Log.Debug("ImageFilm Exception: ", ex); } }
private void BgWorker_DoWork(object sender, DoWorkEventArgs e) { try { tempPathFolder = Path.Combine(Settings.ApplicationTempFolder, Path.GetRandomFileName()); try { if (!Directory.Exists(tempPathFolder)) { Directory.CreateDirectory(tempPathFolder); } } catch (Exception) { return; } zipPath = _saveFileDialog.SelectedPath;//Path.Combine(FolderNameZip.ToString(), "ZIPFiles"); if (!Directory.Exists(zipPath)) { Directory.CreateDirectory(zipPath); } string _ZipFileName = "zp_" + DateTime.Now.Ticks.ToString() + ".zip"; zipPath = Path.Combine(zipPath, _ZipFileName); //if (ImageFilm == true) { ImageFilmGeneration(tempPathFolder); } total = ZipImageCount; foreach (var img in ImagesZip) //todaysFiles is list of file names (with full path) to be zipped { count++; bgWorker.ReportProgress(count); if (img.IsZIPSelected == true) { Bitmap image = new Bitmap(img.Path); Bitmap newImage = new Bitmap((int)ExportWidthZip, (int)ExportHeightZip, PixelFormat.Format24bppRgb); string tempPath = Path.Combine(tempPathFolder, img.FileName); // Draws the image in the specified size with quality mode set to HighQuality using (Graphics graphics = Graphics.FromImage(newImage)) { graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.DrawImage(image, 0, 0, (int)ExportWidthZip, (int)ExportHeightZip); graphics.Dispose(); } using (var ms = new MemoryStream()) { using (FileStream fs = new FileStream(tempPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { if (SelectedFileExtension.ToUpper() == "BMP") { newImage.Save(ms, ImageFormat.Bmp); } else if (SelectedFileExtension.ToUpper() == "PNG") { newImage.Save(ms, ImageFormat.Png); } else { newImage.Save(ms, ImageFormat.Jpeg); } byte[] bytes = ms.ToArray(); fs.Write(bytes, 0, bytes.Length); fs.Dispose(); } ms.Dispose(); } using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update)) { string _fileName = Path.GetFileNameWithoutExtension(img.FileName) + "." + SelectedFileExtension;; archive.CreateEntryFromFile(tempPath, _fileName); successful = true; } image.Dispose(); newImage.Dispose(); GC.Collect(); } } bgWorker.ReportProgress(count + 1); if (ImageFilm == true) { ImageFilmGeneration(tempPathFolder); } try { if (!Directory.Exists(tempPathFolder)) { } { if (ImageFilm == true) { if (SelectedFileExtension == "" || SelectedFileExtension == null) { SelectedFileExtension = "Jpg"; } using (ZipArchive archive = System.IO.Compression.ZipFile.Open(zipPath, ZipArchiveMode.Update)) { archive.CreateEntryFromFile(Path.Combine(tempPathFolder, "imagefilm." + SelectedFileExtension), "imagefilm." + SelectedFileExtension); } } } } catch (Exception ex) { Log.Debug("ZipArchive Exception: ", ex); MessageBox.Show("Unable to export images. Try after sometime...!", "360 PC Tool | Zip Export", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { Log.Debug("Zip images exception: ", ex); } }