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

  • 相关阅读:
    Shell 脚本读取文件中的每行
    Linux中的内存管理机制
    CPU Cache 学习(一)
    linux系统层次(转)
    linux下的一些常用命令
    几个关于Linux进程fork()的题目
    GDB调试工具
    POSIX thread library 简介I
    Scheme Programming language II
    Google Chrome浏览器标签页之间的自动切换
  • 原文地址:https://www.cnblogs.com/sunhappy0318/p/SLT_UIElement.html
Copyright © 2011-2022 走看看