Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否在listview中显示图像[]?_C#_Winforms_Image_Listview - Fatal编程技术网

C# 是否在listview中显示图像[]?

C# 是否在listview中显示图像[]?,c#,winforms,image,listview,C#,Winforms,Image,Listview,我想在列表视图中显示图像[],但不知道如何显示。我在网上搜索了一下,大家一致认为最好使用ImageList。它工作正常,显示正确,但不适合我的需要 如何将此代码转换为使用图像[]而不是图像列表 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string dir = (string)e.Argument; imageArr = Directory.GetFiles(dir,

我想在列表视图中显示
图像[]
,但不知道如何显示。我在网上搜索了一下,大家一致认为最好使用
ImageList
。它工作正常,显示正确,但不适合我的需要

如何将此代码转换为使用
图像[]
而不是
图像列表

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

     string dir = (string)e.Argument;
     imageArr = Directory.GetFiles(dir, "*.jpeg", SearchOption.AllDirectories);

     picList = new ImageList();

     toolStripStatusLabel1.Text = "Generating thumbnails...";

     for (int i = 0; i < imageArr.Length; i++)
     {
         Image img = Image.FromFile(imageArr[i]);
         int width = img.Width / 10;
         int height = img.Height / 10;
         Image pic = img.GetThumbnailImage(width, height, null, new IntPtr());
         picList.Images.Add(pic);

         int procent = ((i + 1) * 100) / imageArr.Length;
         bw.ReportProgress(procent);
     }

     bw.ReportProgress(0);
     toolStripStatusLabel1.Text = "";

     populateListView(picList);
 }

 private delegate void populateListViewDelegate(ImageList picList);

 private void populateListView(ImageList picList)
 {
     if (InvokeRequired)
     {
         this.Invoke(new populateListViewDelegate(populateListView), picList);
         return;
     }

     Size thumbSize = new Size(200, 141);
     listView1.View = View.LargeIcon;
     picList.ImageSize = thumbSize;
     listView1.LargeImageList = picList;

     toolStripStatusLabel1.Text = "Adding thumbnails to listview...";

     for (int i = 0; i < picList.Images.Count; i++)
     {
         ListViewItem item = new ListViewItem();
         item.ImageIndex = i;
         listView1.Items.Add(item);

         int procent = ((i + 1) * 100) / picList.Images.Count;
         bw.ReportProgress(procent);
     }

     bw.ReportProgress(0);
     toolStripStatusLabel1.Text = "";
 }
private void backgroundWorker1\u DoWork(对象发送方,DoWorkEventArgs e)
{
string dir=(string)e.Argument;
imageArr=Directory.GetFiles(dir,“*.jpeg”,SearchOption.AllDirectories);
picList=新的ImageList();
toolStripStatusLabel1.Text=“生成缩略图…”;
对于(int i=0;i
显然,
int-width
int-height
不起作用,因为ImageList对所有图像都有相同的大小,如果我理解正确的话,但我当时不知道,这就是为什么我懒惰的自己把代码留在那里的原因

基本上,我前面提到的“需求”是这些“缩略图”应该能够有不同的大小


有没有关于解决方法的帮助、我的问题的提示或者我应该采取不同的方法?

在添加图像之前,您需要设置
ImageSize
。如果更改
图像大小
,则会删除以前添加的所有图像


在添加任何图像之前,您可能还需要将ColorDepth设置为32位。

如果需要显示不同大小的缩略图,ListView将帮不上忙--ListView不能显示不同高度的行。如果只显示图像,则列表框更适合您的需要。但是,理论上,图像的大小可能不同,而行的大小是一致的。难道不能设置一个缩略图的大小限制,使其不超过行的大小吗?我需要一次显示几千个缩略图,最好是大小可以不同,但差异会非常小,例如由于方向的差异;风景画,肖像画。有关于如何/做什么的提示吗?