Пример #1
0
        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            MgMapViewerProvider provider  = _viewer.GetProvider();
            MgSelectionBase     selection = _viewer.GetSelection();
            MgMapBase           map       = _viewer.GetMap();
            MgPoint             pt        = map.ViewCenter;
            MgCoordinate        coord     = pt.Coordinate;
            float leftMargin = e.MarginBounds.Left;
            float topMargin  = e.MarginBounds.Top;
            float yPos       = topMargin;
            float pageHeight = e.MarginBounds.Height;

            //Write title
            var titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, GraphicsUnit.Point);
            var sizeTitle = e.Graphics.MeasureString(txtTitle.Text, titleFont);

            e.Graphics.DrawString(txtTitle.Text, titleFont, Brushes.Black, new PointF(leftMargin, yPos));

            yPos += (sizeTitle.Height * 1.1f);

            var scaleFont = SystemFonts.CaptionFont;
            var scaleStr  = string.Format("{0} 1 : {1}", Strings.TextScale, _viewer.GetMap().ViewScale); //NOXLATE
            var sizeScale = e.Graphics.MeasureString(scaleStr, scaleFont);

            //Scale to fit within this page
            var imgHeight = (int)(pageHeight - (sizeTitle.Height * 1.1f) - (sizeScale.Height * 1.1f));
            var imgWidth  = e.MarginBounds.Width;

            using (var state = provider.CreateTransientState())
            {
                var tempState = new MgMapDisplayParameters(coord.X, coord.Y, map.ViewScale, imgWidth, imgHeight, (int)numDPI.Value);
                state.PushState(tempState);
                MgByteReader br = provider.RenderMap(selection, "PNG"); //NOXLATE
                using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                {
                    Image img = Image.FromStream(stream);
                    e.Graphics.DrawImage(img, leftMargin, yPos, imgWidth, imgHeight);
                    img.Dispose();
                }
            }

            yPos += imgHeight;

            //Render scale
            if (chkScale.Checked)
            {
                e.Graphics.DrawString(scaleStr, scaleFont, Brushes.Black, new PointF(leftMargin, yPos));
            }

            e.HasMorePages = false;
        }
Пример #2
0
        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            MgMapViewerProvider provider = _viewer.GetProvider();
            MgSelectionBase selection = _viewer.GetSelection();
            MgMapBase map = _viewer.GetMap();
            MgPoint pt = map.ViewCenter;
            MgCoordinate coord = pt.Coordinate;
            float leftMargin = e.MarginBounds.Left;
            float topMargin = e.MarginBounds.Top;
            float yPos = topMargin;
            float pageHeight = e.MarginBounds.Height;

            //Write title
            var titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, GraphicsUnit.Point);
            var sizeTitle = e.Graphics.MeasureString(txtTitle.Text, titleFont);
            e.Graphics.DrawString(txtTitle.Text, titleFont, Brushes.Black, new PointF(leftMargin, yPos));

            yPos += (sizeTitle.Height * 1.1f);

            var scaleFont = SystemFonts.CaptionFont;
            var scaleStr = string.Format("{0} 1 : {1}", Strings.TextScale, _viewer.GetMap().ViewScale); //NOXLATE
            var sizeScale = e.Graphics.MeasureString(scaleStr, scaleFont);

            //Scale to fit within this page
            var imgHeight = (int)(pageHeight - (sizeTitle.Height * 1.1f) - (sizeScale.Height * 1.1f));
            var imgWidth = e.MarginBounds.Width;

            using (var state = provider.CreateTransientState())
            {
                var tempState = new MgMapDisplayParameters(coord.X, coord.Y, map.ViewScale, imgWidth, imgHeight, (int)numDPI.Value);
                state.PushState(tempState);
                MgByteReader br = provider.RenderMap(selection, "PNG"); //NOXLATE
                using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                {
                    Image img = Image.FromStream(stream);
                    e.Graphics.DrawImage(img, leftMargin, yPos, imgWidth, imgHeight);
                    img.Dispose();
                }
            }

            yPos += imgHeight;

            //Render scale
            if (chkScale.Checked)
                e.Graphics.DrawString(scaleStr, scaleFont, Brushes.Black, new PointF(leftMargin, yPos));

            e.HasMorePages = false;
        }
Пример #3
0
        private void btnRenderMap1_Click(object sender, EventArgs e)
        {
            //Note we're casting to mg-desktop specific subclasses as this is what mg-desktop rendering APIs expect
            MgdMap map = (MgdMap)_viewer.GetMap();
            MgdSelection selection = (MgdSelection)_viewer.GetSelection();
            MgMapViewerProvider provider = _viewer.GetProvider();
            MgdRenderingService renderSvc = (MgdRenderingService)provider.CreateService(MgServiceType.RenderingService);
            MgPoint centerPt = map.ViewCenter;
            MgCoordinate centerCoord = centerPt.Coordinate;

            //MgdTransientMapState is a helper class which lets us apply transient state to a map, which is automatically
            //undone on disposal. This is how we can render custom views of a map with specific display parameters without
            //permanently changing the display parameters used by the map viewer
            using (MgTransientMapState tempState = provider.CreateTransientState(map))
            {
                MgMapDisplayParameters state = new MgMapDisplayParameters(centerCoord.X, centerCoord.Y, 4000, 640, 480, 96);
                tempState.PushState(state);

                MgByteReader br = renderSvc.RenderMap(map, selection, "PNG");
                using (SaveFileDialog save = new SaveFileDialog())
                {
                    save.Filter = "Portable Network Graphics (*.png)|*.png";
                    if (save.ShowDialog() == DialogResult.OK)
                    {
                        //MgReadOnlyStream is a stream adapter class that provides a .net stream
                        //interface to the MgByteReader, allowing MgByteReader objects to be used
                        //anywhere a System.IO.Stream is expected.
                        using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                        {
                            Image img = Image.FromStream(stream);
                            img.Save(save.FileName);
                            MessageBox.Show("Image saved to: " + save.FileName);
                        }
                    }
                    br.Dispose();
                }
            }
        }