Example #1
0
        GetImages
        (
            NodeXLControl oNodeXLControl,
            Boolean bUseFixedAspectRatio,
            out Byte [] abtFullSizeImage,
            out Byte [] abtThumbnail
        )
        {
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert(oNodeXLControl.ActualWidth >= MinimumNodeXLControlWidth);
            Debug.Assert(oNodeXLControl.ActualHeight >= MinimumNodeXLControlHeight);

            Size oFullSizeImageSizePx = GetFullSizeImageSizePx(oNodeXLControl,
                                                               bUseFixedAspectRatio);

            Image oFullSizeImage = oNodeXLControl.CopyGraphToBitmap(
                oFullSizeImageSizePx.Width, oFullSizeImageSizePx.Height);

            Size oThumbnailImageSizePx = GetThumbnailImageSizePx(
                oFullSizeImageSizePx);

            Image oThumbnail = oFullSizeImage.GetThumbnailImage(
                oThumbnailImageSizePx.Width, oThumbnailImageSizePx.Height,
                () => { return(false); }, IntPtr.Zero);

            abtFullSizeImage = ImageToBytes(oFullSizeImage);
            abtThumbnail     = ImageToBytes(oThumbnail);

            oFullSizeImage.Dispose();
            oThumbnail.Dispose();
        }
Example #2
0
        SaveGraphImageFile
        (
            NodeXLControl oNodeXLControl,
            String sWorkbookFilePath
        )
        {
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert(!String.IsNullOrEmpty(sWorkbookFilePath));

            AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings =
                new AutomatedGraphImageUserSettings();

            Size oImageSizePx = oAutomatedGraphImageUserSettings.ImageSizePx;

            Bitmap oBitmapCopy = oNodeXLControl.CopyGraphToBitmap(
                oImageSizePx.Width, oImageSizePx.Height);

            ImageFormat eImageFormat =
                oAutomatedGraphImageUserSettings.ImageFormat;

            String sImageFilePath = Path.ChangeExtension(sWorkbookFilePath,
                                                         SaveableImageFormats.GetFileExtension(eImageFormat));

            try
            {
                oBitmapCopy.Save(sImageFilePath, eImageFormat);
            }
            catch (System.Runtime.InteropServices.ExternalException)
            {
                // When an image file already exists and is read-only, an
                // ExternalException is thrown.
                //
                // Note that this method is called from the
                // ThisWorkbook.GraphLaidOut event handler, so this exception can't
                // be handled by a TaskAutomator.AutomateThisWorkbook() exception
                // handler.

                FormUtil.ShowWarning(String.Format(
                                         "The image file \"{0}\" couldn't be saved.  Does a read-only"
                                         + " file with the same name already exist?"
                                         ,
                                         sImageFilePath
                                         ));
            }
            finally
            {
                oBitmapCopy.Dispose();
            }
        }