SaveObject ( Object oObject, String sFileName ) { Debug.Assert(oObject is GraphImageSource); Debug.Assert(!String.IsNullOrEmpty(sFileName)); GraphImageSource oGraphImageSource = (GraphImageSource)oObject; if (m_oSaveFileDialog.FilterIndex <= SaveableImageFormats.ImageFormats.Length) { // Tell the NodeXLControl to copy its graph to a bitmap, then let // the base class save it. Bitmap oBitmapCopy = oGraphImageSource.NodeXLControl.CopyGraphToBitmap( oGraphImageSource.Width, oGraphImageSource.Height); base.SaveObject(oBitmapCopy, sFileName); oBitmapCopy.Dispose(); } else { // The graph must be saved as an XPS. oGraphImageSource.NodeXLControl.SaveToXps( new System.Windows.Size( ToWpsUnits(oGraphImageSource.Width), ToWpsUnits(oGraphImageSource.Height) ), sFileName ); } }
ShowDialogAndSaveGraphImage ( ExcelTemplateNodeXLControl nodeXLControl, Int32 width, Int32 height ) { Debug.Assert(nodeXLControl != null); Debug.Assert(width > 0); Debug.Assert(height > 0); AssertValid(); // Let the base class do most of the work. The actual saving will be // done by SaveObject() in this class. Wrap the information required // by SaveObject(). GraphImageSource oGraphImageSource = new GraphImageSource(); oGraphImageSource.NodeXLControl = nodeXLControl; oGraphImageSource.Width = width; oGraphImageSource.Height = height; return(ShowDialogAndSaveObject(oGraphImageSource)); }
//************************************************************************* // Method: ShowDialogAndSaveGraphImage() // /// <summary> /// Shows the file save dialog and saves the image to the selected file. /// </summary> /// /// <param name="nodeXLControl"> /// The control the image will come from. /// </param> /// /// <param name="width"> /// Width of the image to save. If saving to XPS, the units are 1/100 of /// an inch. Otherwise, the units are pixels. /// </param> /// /// <param name="height"> /// Height of the image to save. If saving to XPS, the units are 1/100 of /// an inch. Otherwise, the units are pixels. /// </param> /// /// <returns> /// DialogResult.OK if the user selected a file name and the image was /// successfully saved. /// </returns> /// /// <remarks> /// This method allows the user to select an image file name and format. /// It then saves the image in the selected format. /// </remarks> //************************************************************************* public DialogResult ShowDialogAndSaveGraphImage( ExcelTemplateNodeXLControl nodeXLControl, Int32 width, Int32 height ) { Debug.Assert(nodeXLControl != null); Debug.Assert(width > 0); Debug.Assert(height > 0); AssertValid(); // Let the base class do most of the work. The actual saving will be // done by SaveObject() in this class. Wrap the information required // by SaveObject(). GraphImageSource oGraphImageSource = new GraphImageSource(); oGraphImageSource.NodeXLControl = nodeXLControl; oGraphImageSource.Width = width; oGraphImageSource.Height = height; return ( ShowDialogAndSaveObject(oGraphImageSource) ); }