zoukankan      html  css  js  c++  java
  • wpf呈现UIElment的缩略图

    在msdn上面介绍两种方法:

    1、使用RenderTargetBitmap

    2、使用VisualBrush

    使用第一种方式是,首先按UIElement的原始尺寸转换成位图,放到Image控件里面,通过缩放矩阵编写你想要的缩略图,代码:

     1             RenderTargetBitmap tRenderTargetBitmap = new RenderTargetBitmap((int)tPageNode.Width, (int)tPageNode.Height, 1 / 96, 1 / 96, PixelFormats.Default);
     2             tRenderTargetBitmap.Render(tPageNode);
     3             Image tImage = new Image();
     4             tImage.Source = tRenderTargetBitmap;
     5             tImage.Width = tPageNode.Width / 8;
     6             tImage.Height = tPageNode.Height / 8;
     7             double tWidthX = 100 / tPageNode.Width;
     8             double tHeightX = 75 / tPageNode.Height;
     9             ScaleTransform tScaleTransform = new ScaleTransform();
    10             tScaleTransform.ScaleX = tWidthX;
    11             tScaleTransform.ScaleY = tHeightX;
    12             tImage.RenderTransform = tScaleTransform;

    使用第二种方法:直接把UIElement赋值给VisualBrush,通过Rectangle呈现,设置Rectangle的大小,代码:

     VisualBrush myVisualBrush = new VisualBrush();
                myVisualBrush.Visual = tPageNode;
                Rectangle myRectangle = new Rectangle();
                myRectangle.Width = 100;
                myRectangle.Height = 100;
                myRectangle.Stroke = Brushes.Black;
                myRectangle.Margin = new Thickness(5, 0, 5, 0);
                myRectangle.Fill = myVisualBrush;
                tPageCanvas.Children.Add(myRectangle);

    第二种方法比第一种方法表现优势在于:可以实时刷新UIElement的内容、呈现的内容相对比较清晰。

  • 相关阅读:
    云计算 备忘录
    python 备忘录
    Linux 备忘录
    appium自动化的一个实例
    appium环境的搭建
    四则运算2单元测试
    四则运算2
    四则运算2程序设计思路
    上课未及时完成的原因
    随机生成30道四则运算题程序设计
  • 原文地址:https://www.cnblogs.com/sunhappy0318/p/SLT_UIElement.html
Copyright © 2011-2022 走看看