繁体   English   中英

如何打开仅将指定文件显示为缩略图的窗口? (使用Visual Studio C#)

[英]How do I open a window showing only specified files as thumbnails? (using visual studio c#)

我有超过1000张图像需要分类。 但是为了简化起见,假设我的硬盘驱动器上有以下文件:

 C:\a.jpg
 C:\b.jpg
 C:\c.jpg
 C:\d.jpg
 C:\e.jpg

该程序将确定需要显示哪些文件并将它们存储在数组中:

 string[] filesToDisplay = new string[] { "C:\b.jpg", "C:\e.jpg" };

我想打开一个窗口,该窗口仅以缩略图形式显示filesToDisplay的内容,因此我可以单击并打开它们。 这将使我只能对选定的图像进行排序,而不是全部。

到目前为止我尝试过的是:

到目前为止,我已经尝试打开资源管理器窗口,但是我无法弄清楚如何仅选择特定文件。 使用类似的时间:

 System.Diagnostics.Process.Start("explorer.exe", argument);

我也考虑过使用IExplorerBrowser,但它看起来非常复杂,我不确定它是否支持缩略图?

谢谢阅读

我认为没有办法仅使用资源管理器显示某些图像,但是您可以将它们添加到ListBox并在DoubleClick上打开文件。

WPF粗略示例:

码:

using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WpfApplication13
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private ObservableCollection<string> _files = new ObservableCollection<string>();
        private string _selectedFile;

        public MainWindow()
        {
            InitializeComponent();

            foreach (var file in Directory.GetFiles(@"C:\"))
            {
                Files.Add(file);
            }
        }

        void Item_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Process.Start(SelectedFile);
        }

        public ObservableCollection<string> Files
        {
            get { return _files; }
            set { _files = value; }
        }

        public string SelectedFile
        {
            get { return _selectedFile; }
            set { _selectedFile = value; NotifyPropertyChanged("SelectedFile"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

XAML:

<Window x:Class="WpfApplication13.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="400" Width="400" Name="UI"  WindowStartupLocation="CenterScreen">
    <Grid DataContext="{Binding ElementName=UI}">
        <ListBox ItemsSource="{Binding Files}" SelectedItem="{Binding SelectedFile}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListBox.Resources>
                <Style TargetType="ListBoxItem">
                    <EventSetter Event="MouseDoubleClick" Handler="Item_MouseDoubleClick" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="BorderBrush" Value="Black" />
                    <Setter Property="Margin" Value="2" />
                </Style>
            </ListBox.Resources>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel IsItemsHost="True" ItemHeight="50" ItemWidth="50"  />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Image Source="{Binding}" Margin="2"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

结果:

在此处输入图片说明

您可以使用Directory-class( link )和GetFiles()-Method( link )搜索要显示为缩略图的文件。

您可以在ListView中显示的那些文件。

在这里,您可以找到有关如何为文件创建缩略图的一些提示: 获取任何文件的缩略图,不仅是Windows XP / Vista上的图像文件

如果只想显示图像文件,则可以通过这种方式创建缩略图

Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM