相关疑难解决方法(0)

ImageList:处理原始图像会将其从列表中删除

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应该创建一个图像副本?

.net c# system.drawing imagelist winforms

3
推荐指数
1
解决办法
1099
查看次数

标签 统计

.net ×1

c# ×1

imagelist ×1

system.drawing ×1

winforms ×1