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


C# Control.Measure方法代码示例

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


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

示例1: ScreenCapture

        public static void ScreenCapture(Control control, string filename)
        {
            try
            {
                // The BitmapSource that is rendered with a Visual.
                control.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                Size size = control.DesiredSize;
                int width = (int) size.Width;
                int height = (int) size.Height;
                control.Arrange(new Rect(0, 0, width, height));
                var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
                rtb.Render(control);

                // Encoding the RenderBitmapTarget as a PNG file.
                var png = new PngBitmapEncoder();
                png.Frames.Add(BitmapFrame.Create(rtb));
                using (Stream stm = File.Create(filename))
                {
                    png.Save(stm);
                }
            }
            finally
            {
            }
        }
开发者ID:staxmanade,项目名称:ApprovalTests.Net,代码行数:25,代码来源:WpfUtils.cs

示例2: getImageFromControl

        /// <summary>
        /// Convert any control to a PngBitmapEncoder
        /// </summary>
        /// <param name="controlToConvert">The control to convert to an ImageSource</param>
        /// <returns>The returned ImageSource of the controlToConvert</returns>
        private static PngBitmapEncoder getImageFromControl(Control controlToConvert)
        {
            // save current canvas transform
            Transform transform = controlToConvert.LayoutTransform;

            // get size of control
            Size sizeOfControl = new Size(controlToConvert.ActualWidth, controlToConvert.ActualHeight);
            // measure and arrange the control
            controlToConvert.Measure(sizeOfControl);
            // arrange the surface
            controlToConvert.Arrange(new Rect(sizeOfControl));

            // craete and render surface and push bitmap to it
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)sizeOfControl.Width, (Int32)sizeOfControl.Height, 96d, 96d, PixelFormats.Pbgra32);
            // now render surface to bitmap
            renderBitmap.Render(controlToConvert);
            
            // encode png data
            PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
            // puch rendered bitmap into it
            pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));

            // return encoder
            return pngEncoder;
        }
开发者ID:SomeGuyinIN,项目名称:hefnycopter,代码行数:30,代码来源:Control2ImageConverter.cs


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