在WPF中创建像Powerpoint thumnail的缩略图预览 [英] Create Thumbnail Preview like Powerpoint thumnail in WPF

查看:74
本文介绍了在WPF中创建像Powerpoint thumnail的缩略图预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个wpf应用程序,其中两个窗格类似于powerpoint应用程序:

I have a wpf application with two panes similar to powerpoint application:


    < li style ="margin:0px 0px 0.5em; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; font-family:inherit; vertical -align:baseline">
    左窗格,显示列表框中所有面板的列表

  • 右侧窗格,显示所选面板


在列表框中,我想将面板显示为缩略图,并在右窗格中将新控件添加到面板时更新缩略图。

In the listbox I want to display panel as thumbnail and update the thumbnail as an when new controls are added to panel in right pane.


就像powerpoint应用程序缩略图行为一样。

Just like powerpoint application thumbnail behaviour.

推荐答案



我有一个wpf应用程序有两个类似于powerpoint应用程序的窗格:

I have a wpf application with two panes similar to powerpoint application:



  • 左侧窗格,显示列表框中所有面板的列表

  • 右侧窗格,显示所选面板


在列表框中,我想将面板显示为缩略图,并在右窗格中将新控件添加到面板时更新缩略图。

In the listbox I want to display panel as thumbnail and update the thumbnail as an when new controls are added to panel in right pane.


就像powerpoint应用程序缩略图行为一样。

Just like powerpoint application thumbnail behaviour.




嗨   Sharda.Iyer,



在WPF中,您可以获取在画布上呈现的任何内容(控件或窗口区域)并将其作为位图文件转储。 



因为在WPF中创建图像和形状相当容易。使用
RenderTargetBitmap
PngBitmapEncoder / GifBitmapEncoder / JpegBitmapEncoder 我们可以捕获一个窗口区域。并使用
BitmapEncoder 框架属性将其分配给图像源。



你可以将窗口分为两个半左右面板。缩略图行为将显示在左侧面板缩略图上。



您可以通过集合存储控件并快速通过索引找到它们。 
$


然后,通过以下方法为您的窗口(控件或窗口区域)创建缩略图。


Hi    Sharda.Iyer,

In WPF that you can take just about anything that you render on the canvas(controls or a region of window) and dump it out as a bitmap file. 

Since it's fairly easy to create images and shapes in WPF. By using RenderTargetBitmap and PngBitmapEncoder/GifBitmapEncoder/JpegBitmapEncoder we can capture a region of window. and by using the BitmapEncoder frame Property assigned it to Image Source.

You can divided the window by two half and left and right panel. The the thumbnail behaviour will be displayed on the left panel thumbnail.

You can store your controls through collections and quickly locate them through indexes. 

Then, Create thumbnails for your window(controls or a region of window) by doing the following method.

private void Getthumbnailpic( )
{
    int Height = (int)this.yourcontrol.ActualHeight;
    int Width = (int)this.yourcontrol.ActualWidth;
    RenderTargetBitmap bmp = new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
    bmp.Render(this.yourcontrol);
    BitmapEncoder encoder;            
    if (Extension == ".gif") 
        encoder = new GifBitmapEncoder();            
    else if (Extension == ".png")
        encoder = new PngBitmapEncoder();            
    else if (Extension == ".jpg")
        encoder = new JpegBitmapEncoder();            
    else
        return;
    encoder.Frames.Add(BitmapFrame.Create(bmp));

             //       RenderTargetBitmap renderTargetBitmap =
     //new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
     //       renderTargetBitmap.Render(yourcontrol);
     //       PngBitmapEncoder pngImage = new PngBitmapEncoder();
     //       pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
  
}




以下链接供您参考。



将WPF容器呈现为位图:
¥b $ b $


此外,如果您可以通过将有用的帖子标记为答案来关闭该主题,将不胜感激。如果他们遇到类似问题,这将有助于其他成员快速找到解决方案。如果您有新问题,可以开始新的
帖子。




最好的问候,

$
Yong Lu




The following links for your reference.

Rendering a WPF Container to Bitmap:


Besides, It would be appreciated if you could close the thread by marking helpful posts as an answer. This will help other members to find the solution quickly if they have faced the similar issue. If you have a new question you can start a new thread.

Best Regards,

Yong Lu


这篇关于在WPF中创建像Powerpoint thumnail的缩略图预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆