private void OnSaveButtonClick(object sender, EventArgs e) { List <Duple <ILineItem, float> > oldThicknesses = new List <Duple <ILineItem, float> >(); bool exception = false; bool oldPenWidthScaled = m_Mp.IsPenWidthScaled; try { float dpi = (float)m_DpiUpDown.Value; m_Mp.m_Dpi = dpi; if (dpi > 96) { m_Mp.IsPenWidthScaled = true; } float widthInUnknownUnits = (float)m_WidthUpDown.Value; float heightInUnknownUnits = (float)m_HeightUpDown.Value; bool isInInches = m_InchesRadio.Checked; float scaleFactor; if (isInInches) { scaleFactor = 1; } else { scaleFactor = 0.393700787f; } float widthInInches = widthInUnknownUnits * scaleFactor; float heightInInches = heightInUnknownUnits * scaleFactor; Size pixelDimensions = new Size((int)(widthInInches * dpi + 0.5), (int)(heightInInches * dpi + 0.5)); //int lineWidth = (int)m_LineWidthUpDown.Value; //foreach (GraphPane gp in m_Mp.PaneList) //{ // foreach (CurveItem ci in gp.CurveList) // { // if (ci is ILineItem) // { // float oldThickness = ((ILineItem)ci).Thickness; // if (oldThickness < lineWidth) // { // oldThicknesses.Add(new Duple<ILineItem, float>((ILineItem)ci, oldThickness)); // ((ILineItem)ci).Thickness = lineWidth; // } // } // } //} SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "PNG Format (*.png)|*.png|" + "Gif Format (*.gif)|*.gif|" + "Jpeg Format (*.jpg)|*.jpg|" + "Tiff Format (*.tif)|*.tif|" + "Bmp Format (*.bmp)|*.bmp"; if (saveDlg.ShowDialog() != DialogResult.OK) { return; } ImageFormat format = ImageFormat.Png; if (saveDlg.FilterIndex == 2) { format = ImageFormat.Gif; } else if (saveDlg.FilterIndex == 3) { format = ImageFormat.Jpeg; } else if (saveDlg.FilterIndex == 4) { format = ImageFormat.Tiff; } else if (saveDlg.FilterIndex == 5) { format = ImageFormat.Bmp; } Stream myStream = saveDlg.OpenFile(); if (myStream != null) { using (Image i = m_Mp.GetImage(pixelDimensions.Width, pixelDimensions.Height, dpi)) { i.Save(myStream, format); } myStream.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); exception = true; } finally { m_Mp.m_Dpi = 72; m_Mp.IsPenWidthScaled = oldPenWidthScaled; foreach (Duple <ILineItem, float> curveAndThickness in oldThicknesses) { curveAndThickness.Item1.Thickness = curveAndThickness.Item2; } if (!exception) { Close(); } } }