Beispiel #1
0
        public static void ExportToPng(GridView gridView, string path, int width, int height)
        {
            var adjusted    = gridView.GetAdjustedWidthHeight();
            var widths      = adjusted.Item1;
            var heights     = adjusted.Item2;
            var totalWidth  = widths.Sum();
            var totalHeight = heights.Sum();

            var file = Path.GetTempFileName();

            var canvas = new Bitmap(width, height);

            using (var g = Graphics.FromImage(canvas))
            {
                g.FillRectangle(Brushes.White, new Rectangle(0, 0, width, height));

                var modelCount = 0;
                var hp         = 0.0;
                foreach (var h in heights)
                {
                    var hr = h / totalHeight;
                    var wp = 0.0;
                    foreach (var w in widths)
                    {
                        var wr = w / totalWidth;
                        if (modelCount < gridView.Models.Count)
                        {
                            var model = gridView.Models[modelCount];
                            ModelExporter.ExportToPng(model, file, (int)(wr * width), (int)(hr * height));
                            using (var image = Image.FromFile(file))
                            {
                                g.DrawImage(image, new Point((int)(wp * width), (int)(hp * height)));
                            }

                            wp += wr;
                        }
                        ++modelCount;
                    }
                    hp += hr;
                }

                canvas.Save(path, ImageFormat.Png);
            }

            File.Delete(file);
        }