Exemplo n.º 1
0
        public static LayoutBitmap ConvertElementToBitmap(LayoutElement le, string filename)
        {
            if (le is LayoutBitmap)
            {
                return(null);
            }
            int padding = le is LayoutLegend ? 10 : 0;

            int width  = Convert.ToInt32(le.SizeF.Width * 3 + 0.5) + padding;
            int height = Convert.ToInt32(le.SizeF.Height * 3 + 0.5);

            if (le is LayoutMap)
            {
                width  = Convert.ToInt32(width * ScreenHelper.LogicToScreenDpi);
                height = Convert.ToInt32(height * ScreenHelper.LogicToScreenDpi);
            }

            using (var temp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
            {
                temp.SetResolution(96, 96);
                temp.MakeTransparent();

                using (var g = Graphics.FromImage(temp))
                {
                    g.PageUnit = GraphicsUnit.Pixel;
                    g.ScaleTransform(300F / 100F, 300F / 100F);

                    if (!(le is LayoutMap))
                    {
                        g.TranslateTransform(-le.LocationF.X, -le.LocationF.Y);
                    }

                    le.DrawElement(g, false, false);
                }

                temp.SetResolution(300, 300);
                temp.Save(filename);
            }

            var bmp = new LayoutBitmap
            {
                Rectangle   = le.Rectangle,
                Name        = le.Name,
                Filename    = filename,
                Initialized = true
            };

            return(bmp);
        }
Exemplo n.º 2
0
        private void AddBitmap()
        {
            var ofd = new OpenFileDialog
            {
                Filter          = PrintingConstants.BitmapFilter,
                FilterIndex     = 1,
                CheckFileExists = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var newBitmap = new LayoutBitmap {
                    SizeF = new SizeF(100, 100), Filename = ofd.FileName
                };
                _layoutControl.AddElementWithMouse(newBitmap);
            }
        }