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的内容、呈现的内容相对比较清晰。

  • 相关阅读:
    PHP的垃圾回收机制
    python使用httpHandler处理请求案例
    使用python中urllib.request.Request()来构建ua
    Pillow《转载》
    python数据格式化之pprint
    使用Mechanize实现自动化表单处理
    beautifulSoup《转》
    Python3网络爬虫(四):使用User Agent和代理IP隐藏身份《转》
    python urllib和urllib3包使用
    使用Mechanize实现自动化表单处理
  • 原文地址:https://www.cnblogs.com/sunhappy0318/p/SLT_UIElement.html
Copyright © 2011-2022 走看看