src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Utils/ModelUtils.cs
/// <summary>
///     Exports the diagram as an image
/// </summary>
Exports the diagram as an image
Exports the diagram as an image
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.FileDialog.set_Filter(System.String)")]
        [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "tif")]
        [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "png")]
        internal static void ExportAsImage(EntityDesignerDiagram diagram)
        {
            if (diagram != null)
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.Title = Resources.ExportAsImageTitle;
                    dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    dlg.Filter = Resources.ImageFormatBmp + "|*.bmp|" +
                                 Resources.ImageFormatJpeg + "|*.jpg|" +
                                 Resources.ImageFormatGif + "|*.gif|" +
                                 Resources.ImageFormatPng + "|*.png|" +
                                 Resources.ImageFormatTiff + "|*.tif";
                    dlg.FileName = Resources.ExportImage_DefaultFileName;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        var childShapes = diagram.NestedChildShapes;
                        Debug.Assert(childShapes != null && childShapes.Count > 0, "Diagram '" + diagram.Title + "' is empty");
                        if (childShapes != null
                            && childShapes.Count > 0)
                        {
                            Bitmap bmp = null;
                            try
                            {
                                AssociationConnector.ForceDrawOnWhiteBackground = true;
                                AssociationConnector.IsColorThemeSet = false;
                                bmp = diagram.CreateBitmap(childShapes, Diagram.CreateBitmapPreference.FavorSmallSizeOverClarity);
                            }
                            finally
                            {
                                AssociationConnector.ForceDrawOnWhiteBackground = false;
                                AssociationConnector.IsColorThemeSet = false;
                            }
                            var imageFormat = ImageFormat.Bmp;
                            var fi = new FileInfo(dlg.FileName);
                            if (fi.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Jpeg;
                            }
                            else if (fi.Extension.Equals(".gif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Gif;
                            }
                            else if (fi.Extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Png;
                            }
                            else if (fi.Extension.Equals(".tif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Tiff;
                            }
                            using (var fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.ReadWrite))
                            {
                                bmp.Save(fs, imageFormat);
                            }
                        }
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] internal static void ExportAsImage ( EntityDesignerDiagram diagram ) { if ( diagram != null ) { using ( var dlg = new SaveFileDialog ( ) ) { dlg . Title = Resources . ExportAsImageTitle ; dlg . InitialDirectory = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ; dlg . Filter = Resources . ImageFormatBmp + " " + Resources . ImageFormatJpeg + " " + Resources . ImageFormatGif + " " + Resources . ImageFormatPng + " " + Resources . ImageFormatTiff + " " ; dlg . FileName = Resources . ExportImage_DefaultFileName ; if ( dlg . ShowDialog ( ) == DialogResult . OK ) { var childShapes = diagram . NestedChildShapes ; Debug . Assert ( childShapes != null && childShapes . Count > 0 , " " + diagram . Title + " " ) ; if ( childShapes != null && childShapes . Count > 0 ) { Bitmap bmp = null ; try { AssociationConnector . ForceDrawOnWhiteBackground = true ; AssociationConnector . IsColorThemeSet = false ; bmp = diagram . CreateBitmap ( childShapes , Diagram . CreateBitmapPreference . FavorSmallSizeOverClarity ) ; } finally { AssociationConnector . ForceDrawOnWhiteBackground = false ; AssociationConnector . IsColorThemeSet = false ; } var imageFormat = ImageFormat . Bmp ; var fi = new FileInfo ( dlg . FileName ) ; if ( fi . Extension . Equals ( " " , StringComparison . OrdinalIgnoreCase ) ) { imageFormat = ImageFormat . Jpeg ; } else if ( fi . Extension . Equals ( " " , StringComparison . OrdinalIgnoreCase ) ) { imageFormat = ImageFormat . Gif ; } else if ( fi . Extension . Equals ( " " , StringComparison . OrdinalIgnoreCase ) ) { imageFormat = ImageFormat . Png ; } else if ( fi . Extension . Equals ( " " , StringComparison . OrdinalIgnoreCase ) ) { imageFormat = ImageFormat . Tiff ; } using ( var fs = new FileStream ( dlg . FileName , FileMode . Create , FileAccess . ReadWrite ) ) { bmp . Save ( fs , imageFormat ) ; } } } } } }
Exports the diagram as an image
Exports the diagram as an image
// image has a white background - so force the AssociationConnector text to take that into account
diagram
EntityDesignerDiagram