<分区>
我想创建一个界面类似于 Windows Explorer 的程序,其中显示缩略图和名称、大小等,并且正在徘徊要使用什么控件。
我想要它做的是:
- 显示所有图片是代码选择的文件夹。它们可能有数百个,使用数百 MB,所以我需要它只渲染可见部分而不是整个内容
- 允许选择一张或多张图片用于代码的其他部分(应用过滤器、复制到其他地方等)。当然,某些选定的图像可能不可见,因此可能无法呈现
- 它应该允许每个项目使用多行信息(名称、尺寸、日期...)
- 缩略图的大小应该很容易改变,如果一列中的项目多了或少了,我需要重排这些项目(这可以用代码来完成,但我更喜欢它在控件中)。当然这不应该改变选中项的列表(所以选中项不是按行和列标识的,而是按索引标识的)
我现在有的是这个(稍后会转到一个单独的函数)
thumb[] thumbs;
public MainWindow() {
InitializeComponent();
int i;
string[] files=Directory.GetFileSystemEntries(@"C:\images","*.jpg",SearchOption.AllDirectories);
System.Drawing.Size mySize=new System.Drawing.Size(128,128);
thumbs=new thumb[files.Length];
for(i=0; i<files.Length ;i++){
thumbs[i]=new thumb(files[i],mySize);
}
//MessageBox.Show("Loaded "+i.ToString()+" images");
}
还有这个(稍后我可能会改用 Image.GetThumbnailImage()
作为调整大小的基础):
class thumb {
public Bitmap bmp;
public Size originalSize;
public string path;
public thumb(string path, Size targetSize) {
Bitmap tempBmp;
this.path=path;
tempBmp=new Bitmap(path);
originalSize=tempBmp.Size;
bmp=new Bitmap(tempBmp,targetSize);
tempBmp.Dispose(); //get our memory back
}
}