Пример #1
0
        private static Bitmap GenerateBitmap(DiagramArguments arguments, IClassDiagram cd)
        {
            var cdVisual = new ClassDiagramVisual(cd);

            using (var measureBitmap = new Bitmap(1, 1))
                using (var measureGraphics = System.Drawing.Graphics.FromImage(measureBitmap))
                {
                    var graphicContext = new GdiPlusGraphicContext(measureGraphics);

                    cdVisual.Layout(graphicContext);

                    var renderBitmap = new Bitmap(
                        (int)Math.Ceiling(cdVisual.Width + 1),
                        (int)Math.Ceiling(cdVisual.Height + 1));

                    using (var renderGraphics = System.Drawing.Graphics.FromImage(renderBitmap))
                    {
                        renderGraphics.Clear(Color.White);
                        renderGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        renderGraphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.High;
                        renderGraphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                        graphicContext = new GdiPlusGraphicContext(renderGraphics);

                        cdVisual.Draw(graphicContext);
                    }

                    return(renderBitmap);
                }
        }
Пример #2
0
        private static Bitmap GenerateBitmap(DiagramArguments arguments, ISequenceDiagram sequenceDiagram)
        {
            IStyle style;

            switch (arguments.Style)
            {
            case DiagramStyle.Sketchy:
                style = new SketchyStyle();
                break;

            case DiagramStyle.Classic:
                style = new ClassicStyle();
                break;

            default:
                throw new ArgumentOutOfRangeException("style");
            }

            if (arguments.Debug)
            {
                style = new DebugStyle(style);
            }

            var sequenceDiagramVisual = new SequenceDiagramVisual(style, sequenceDiagram);

            using (var measureBitmap = new Bitmap(1, 1))
                using (var measureGraphics = System.Drawing.Graphics.FromImage(measureBitmap))
                {
                    var graphicContext = new GdiPlusGraphicContext(measureGraphics);

                    sequenceDiagramVisual.Layout(graphicContext);

                    var renderBitmap = new Bitmap(
                        (int)Math.Ceiling(sequenceDiagramVisual.Width + 1),
                        (int)Math.Ceiling(sequenceDiagramVisual.Height + 1));

                    using (var renderGraphics = System.Drawing.Graphics.FromImage(renderBitmap))
                    {
                        renderGraphics.Clear(Color.White);
                        renderGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        renderGraphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.High;
                        renderGraphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                        graphicContext = new GdiPlusGraphicContext(renderGraphics);

                        sequenceDiagramVisual.Draw(graphicContext);
                    }

                    return(renderBitmap);
                }
        }