private async void LoadImage(string path) { string filename = Path.GetFileName(path); string extension = Path.GetExtension(path); PictureTabPage tab = new PictureTabPage(filename); tabControl.TabPages.Add(tab); tabControl.SelectedTab = tab; tab.Cursor = Cursors.WaitCursor; try { Image image; if (extension == ".pbm" || extension == ".pgm" || extension == ".ppm") { image = await Anymap.LoadAsync(path); } else { image = Image.FromFile(path); } tab.Image = image; saveAsToolStripMenuItem.Enabled = true; zoomInToolStripMenuItem.Enabled = true; zoomOutToolStripMenuItem.Enabled = true; setZoomToolStripMenuItem.Enabled = true; } catch (Exception ex) { tabControl.TabPages.Remove(tab); MessageBox.Show(string.Format("Error loading {0}!", path), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } tab.Cursor = Cursors.Default; }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl.TabCount < 1) { return; } PictureTabPage tab = (PictureTabPage)tabControl.SelectedTab; Image image = tab.Image; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string path = saveFileDialog.FileName; string extension = Path.GetExtension(saveFileDialog.FileName); Cursor = Cursors.WaitCursor; try { if (extension == ".pbm" || extension == ".pgm" || extension == ".ppm") { Anymap.Save(image, path); } else { image.Save(path); } } catch (Exception) { MessageBox.Show(string.Format("Could not save file as {0}!", path), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor = Cursors.Default; } }