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

  • 相关阅读:
    书签
    jQueryUI Plugin TableSorter的2个widget扩展
    CSS之关于clearfix--清除浮动
    C#中的is关键字原来会做null检查
    jQuery UI 控件之Slider
    延长Nodejs HTTP 的连接时长
    Nodejs的Promise库
    jQuery的选择器中的通配符
    SharePoint Server 2010 中的基本任务
    ajax浅析---ScriptManagerProxy
  • 原文地址:https://www.cnblogs.com/sunhappy0318/p/SLT_UIElement.html
Copyright © 2011-2022 走看看