当前位置: 首页>>代码示例>>C#>>正文


C# MapView.Measure方法代码示例

本文整理汇总了C#中MapView.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# MapView.Measure方法的具体用法?C# MapView.Measure怎么用?C# MapView.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MapView的用法示例。


在下文中一共展示了MapView.Measure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrintMap

        /// <summary>
        // Default print method of the map control,
        /// Exports a map to a byte array
        /// </summary>
        /// <param name="mapView">the mapview containing the content</param>
        /// <param name="useScaling">true, if the contend should be scaled to fit the image size:
        /// false, if the map scale shouldn't be changed.</param>
        /// <param name="description"></param>
        public void PrintMap(MapView mapView, bool useScaling, string description)
        {
            // Open the print dialog.
            PrintDialog print = new PrintDialog();
            if (print.ShowDialog() == false)
                return;

            // Initialize variables.
            PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket);
            System.Windows.Media.Transform oldTransform = null;

            if (useScaling)
            {
                // Set the transform object for scaling.
                double scale = System.Math.Min(capabilities.PageImageableArea.ExtentWidth / mapView.ActualWidth,
                                               capabilities.PageImageableArea.ExtentHeight / mapView.ActualHeight);
                oldTransform = mapView.LayoutTransform;
                mapView.LayoutTransform = new ScaleTransform(scale, scale);
            }

            // Set the size.
            Size oldSize = new Size(mapView.ActualWidth, mapView.ActualHeight);
            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            mapView.Measure(sz);
            ((UIElement)mapView).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            // Print.
            mapView.Printing = true;
            mapView.UpdateLayout();
            print.PrintVisual(mapView, description);
            mapView.Printing = false;

            // Reset the old values.
            if (useScaling)
                mapView.LayoutTransform = oldTransform;
            mapView.Measure(oldSize);
            ((UIElement)mapView).Arrange(new Rect(new Point(0, 0), oldSize));
        }
开发者ID:MuffPotter,项目名称:xservernet-bin,代码行数:46,代码来源:Window1.xaml.cs

示例2: ExportMap

        /// <summary>
        /// Exports a map to a byte array
        /// </summary>
        /// <param name="mapView">the mapview containing the content</param>
        /// <param name="sz">the size of the output image</param>
        /// <param name="useScaling">true, if the contend should be scaled to fit the image size:
        /// false, if the map scale shouldn't be changed.</param>
        /// <returns>The (jpg) image as byte array</returns>
        public byte[] ExportMap(MapView mapView, Size sz, bool useScaling)
        {
            System.Windows.Media.Transform oldTransform = null;

            if (useScaling)
            {
                // Set the transform object for scaling.
                double scale = System.Math.Min(sz.Width / mapView.ActualWidth,
                                               sz.Height / mapView.ActualHeight);
                oldTransform = mapView.LayoutTransform;
                mapView.LayoutTransform = new ScaleTransform(scale, scale);
            }

            // Set the size.
            Size oldSize = new Size(mapView.ActualWidth, mapView.ActualHeight);
            mapView.Measure(sz);
            ((UIElement)mapView).Arrange(new Rect(new Point(0, 0), sz));

            // Print.
            mapView.Printing = true;
            mapView.UpdateLayout();

            RenderTargetBitmap rtb = new RenderTargetBitmap((int)sz.Width, (int)sz.Height, 96d, 96d, PixelFormats.Default);
            rtb.Render(mapView);

            mapView.Printing = false;

            // Reset the old values.
            if (useScaling)
                mapView.LayoutTransform = oldTransform;
            mapView.Measure(oldSize);
            ((UIElement)mapView).Arrange(new Rect(new Point(0, 0), oldSize));

            // encode image
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtb));

            var ms = new MemoryStream();
            encoder.Save(ms);
            ms.Close();
            return ms.ToArray();
        }
开发者ID:MuffPotter,项目名称:xservernet-bin,代码行数:50,代码来源:Window1.xaml.cs


注:本文中的MapView.Measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。