private void CatchEx(Exception ex, int ind = 0) { ImageToSort.Image.Dispose(); Colors.Array = null; Colors.ListOfColors.Clear(); pictureBox1.Image = new Bitmap(5, 5); shakerSortButton.Enabled = false; shellSortButton.Enabled = false; FileExceptionForm ExForm = new FileExceptionForm(ex, ind); ExForm.ShowDialog(); this.Enabled = true; }
private void writeGIF() { SaveFileDialog exportGIF = new SaveFileDialog { Filter = "GIF files (*.gif)|*.gif", RestoreDirectory = true, }; if (exportGIF.ShowDialog() == DialogResult.OK) { SimpleLog.SWatch_start("Exporting file " + exportGIF.FileName); try { using (FileStream fs = new FileStream(exportGIF.FileName, FileMode.Create)) { try { ImageToSort.gifEncoder.Save(fs); } catch (Exception ex) { FileExceptionForm ExForm = new FileExceptionForm(ex, 1); ExForm.Show(); } } } catch (Exception ex) { FileExceptionForm ExForm = new FileExceptionForm(ex, 3); ExForm.Show(); } ImageToSort.gifEncoder.Frames.Clear(); ImageToSort.gifEncoder = null; } GC.Collect(); }
private void writeToolStripMenuItem_Click(object sender, EventArgs e) { if (Colors.ListOfColors.Count == 0) { return; } SaveFileDialog exportFile = new SaveFileDialog { Filter = "Text files (*.txt)|*.txt|CSV files (*.csv)|*.csv|Bitmap pictures (*bmp)|*.bmp", FilterIndex = 1, RestoreDirectory = true }; if (exportFile.ShowDialog() == DialogResult.OK) { SimpleLog.SWatch_start("Exporting file " + exportFile.FileName); if (exportFile.FilterIndex != 3) { try { using (StreamWriter fout = new StreamWriter(exportFile.FileName, false)) { int value = ImageToSort.Height; try { switch (exportFile.FilterIndex) { case 1: fout.WriteLine(value + " " + Colors.ConstantColor); for (int i = 0; i < value * value; i++) { fout.Write(Colors.ListOfColors[i].R + " " + Colors.ListOfColors[i].G + " "); if (i != 0 && i % value == 0) { fout.Write('\n'); } } break; case 2: fout.WriteLine(value + "," + Colors.ConstantColor); for (int i = 0; i < value * value; i++) { fout.Write("\"" + Colors.ListOfColors[i].R + "," + Colors.ListOfColors[i].G + "\""); if (i != 0 && ((i + 1) % value == 0)) { fout.Write('\n'); } else { fout.Write(","); } } break; } } catch (Exception ex) { FileExceptionForm exForm = new FileExceptionForm(ex, 1); exForm.ShowDialog(); } } } catch (Exception ex) { CatchEx(ex, 3); return; } } else { try { using (Bitmap img = ImageToSort.Image) { try { img.Save(exportFile.FileName); } catch (Exception ex) { FileExceptionForm exForm = new FileExceptionForm(ex, 1); exForm.ShowDialog(); } } } catch (Exception ex) { CatchEx(ex, 3); return; } } SimpleLog.SWatch_stop(); } exportFile.Dispose(); }