Question

I have over 1000 images to sort through. But just to simplify, suppose I have the following files on my hard drive:

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

The program will determine which files need to be displayed and store them an array:

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

I would like to have a window open showing only contents of filesToDisplay as thumbnails, so I can then click and open them. This will allow me to only sort through the selected images, rather than all of them.

What I have tried so far:

So far I have tried to open an explorer window, but I cant figure out how to only select specific files. Using sometime like:

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

I have also considered using IExplorerBrowser but it seems very complicated and I'm not sure it it supports thumbnails?

Thanks for reading

Was it helpful?

Solution

I don't think there is a way to display certain Images only using Explorer, However you coul just add them to a ListBox and open the file on DoubleClick.

Rough WPF Example:

Code:

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>

Result:

enter image description here

OTHER TIPS

You could use the Directory-class (link) and the GetFiles()-Method (link) to search for the files you want to display as thumbnails.

Those files you could show in a ListView.

Here you can find some hints of how to create the thumbnails for your files:Get thumbnail of any file, not only image files on Windows XP/Vista

If you only want to show image-files you can create your thumbnails in this way

Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top