ImageList应创建插入其中的所有图像的副本.因此,在将原件添加到列表后处置原件应该是安全的.
为什么以下测试用例失败?
Bitmap test = new Bitmap(128, 128);
ImageList il = new ImageList();
il.Images.Add(test);
Assert.AreEqual(1, il.Images.Count); // OK, image has been inserted
test.Dispose(); // now let's dispose the original
try
{
var retrievalTest = il.Images[0];
}
catch (ArgumentException) // ... but this Exception happens!
{
}
Assert.AreEqual(1, il.Images.Count); // and this will fail
Run Code Online (Sandbox Code Playgroud)
这里似乎发生了这样的事情:当尝试检索图像时,ImageList发现原始文件已被处理,并将其从ImageList中删除.
为什么会发生这种情况,我认为ImageList应该创建一个图像副本?