2013-03-14 100 views
1

看了几个例子,下面的例子我的代码现在看起来像这样(见下文),但不幸的是我得到错误 “'System.Windows.Forms.ImageList''not包含关于“指定者”的定义和没有扩展方法“指定者”接受类型“System.Windows.Forms.ImageList”的第一个参数可以找到(是否缺少using指令或程序集引用?)”将图像列表转换为图像数组

有任何想法吗 ?我可能已经错过了其他职位所示的一部分,但我不这么认为

ImageList Move_list = new ImageList(); 
. 
. 
. 
//Gather the images 
string  path   = "C:/Pictures/Movements/User"; 
string[]  filter  = { ".jpg", ".jpeg"}; 
DirectoryInfo directoryInfo = new DirectoryInfo(path); 
FileInfo[] fileInfo  = directoryInfo.GetFiles(); 
ArrayList  arrayList  = new ArrayList(); 

foreach (FileInfo fi in fileInfo) 
    foreach (string s in filter) 
    if (s == fi.Extension) 
     arrayList.Add(fi.FullName); 

//adding files to image list: 
for (i = 0; i < arrayList.Count; i++) 
{ 
    System.Drawing.Image img = System.Drawing.Image.FromFile(arrayList[i].ToString()); 
    Move_list.Images.Add(img); 
} 

User_moves[0] = Move_list.toArray(); 
+1

请详细说明。您还没有告诉我们“Move_list”或“Move_list.Images”的数据类型,因此很难告诉您如何将其转换为数组。它*看起来像你的班级'Move_list'有某种'Images'集合。如果是'IEnumerable ',你可以简单的说'Image [] x = Move_list.ToArray();' – 2013-03-14 21:56:21

+0

对不起,移动列表是:ImageList Move_list = new ImageList(); – H65 2013-03-14 22:03:18

回答

0

从我所收集,Move_listImageListImageList不执行IQueryableIEnumerableToArraySystem.Linq中定义为这两个接口上的扩展方法。

您应该能够使用Move_list.Images.ToArray(),因为图像是ImageCollection,它确实实现IEnumerable

3

Move_list.Images是您的列表,而不是ImageList。这是一个严重命名的类,但它在Win32中映射了ImageList概念(这是一个处理顺序图像的长位图)。无论如何:

+0

如果你不使用Cast,你会得到一个对象[]而不是Image []。 – cunningdave 2013-03-14 21:53:58

+0

没有运气,doin引发此错误:'System.Data.EnumerableRowCollectionExtensions.Cast (System.Data.EnumerableRowCollection)'是一个'方法',在给定的上下文中无效 – H65 2013-03-14 22:09:15

+0

我的不好,我忘了括号铸造()调用。 – cunningdave 2013-03-15 14:37:38