Exemple #1
0
        public override void Render()
        {
            if (frameCount % blinkFrameInterval == 0)
            {
                renderer.RenderImage("Resources/title.png");
            }
            else if (frameCount % blinkFrameInterval == blinkFrameInterval / 2)
            {
                renderer.RenderImage("Resources/title2.png");
            }

            frameCount++;
        }
        private void SaveImage(FileInfo fileInfo)
        {
            foreach (var node in _resultGraph.Nodes)
            {
                if (node.Tag is PersonNode personNode)
                {
                    node.Description = PersonFormatter.GetName(personNode.Person).Replace("\"", "'");
                }
                else if (node.Tag is ProfileNode profileNode)
                {
                    node.Description = profileNode.Profile.Title.Replace("\"", "'");
                }
            }

            foreach (var edge in _resultGraph.Edges)
            {
                if (_withJobs)
                {
                    PersonNode  personNode;
                    ProfileNode profileNode;

                    if (edge.SourceNode.Tag is PersonNode temp)
                    {
                        personNode  = temp;
                        profileNode = (ProfileNode)edge.TargetNode.Tag;
                    }
                    else
                    {
                        personNode  = (PersonNode)edge.TargetNode.Tag;
                        profileNode = (ProfileNode)edge.SourceNode.Tag;
                    }

                    var jobs = personNode.GetJobs(profileNode);

                    edge.Description = PersonFormatter.GetJob(jobs.First()).Replace("\"", "'");
                }
                else
                {
                    edge.Description = string.Empty;
                }
            }

            var dotText = _resultGraph.ToDotText();

            switch (fileInfo.Extension.ToLower())
            {
            case ".png":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                break;
            }

            case ".svg":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.svg);

                break;
            }

            case ".bmp":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Bmp);

                break;
            }

            case ".tif":
            case ".tiff":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Tiff);

                break;
            }

            case ".jpg":
            case ".jpeg":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.jpg);

                break;
            }

            case ".gif":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Gif);

                break;
            }

            default:
            {
                MessageBox.Show($"Unknown file format: {fileInfo.Extension}", "GraphWiz", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }
            }

            Process.Start(fileInfo.FullName);
        }