【发布时间】:2013-03-03 11:33:21
【问题描述】:
看了几个例子,按照这些例子,我的代码现在看起来像这样(见下文),但不幸的是我收到了错误 “‘System.Windows.Forms.ImageList’不包含‘toArray’的定义,并且找不到接受‘System.Windows.Forms.ImageList’类型的第一个参数的扩展方法‘toArray’(您是否缺少使用指令还是程序集引用?)”
有什么想法吗?我可能错过了其他帖子中显示的部分,但我不这么认为
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();
【问题讨论】:
-
请详细说明。您还没有告诉我们
Move_list或Move_list.Images的数据类型,很难告诉您如何将其转换为数组。它看起来像你的班级Move_list有某种Images集合。如果是IEnumerable<Image>,你可以直接说Image[] x = Move_list.ToArray() ; -
对不起,移动列表是:ImageList Move_list = new ImageList();