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
画像を取得しようとすると、ImageList は元の画像が破棄されていることを発見し、ImageList から削除します。
ImageList はイメージのコピーを作成するはずだと思ったのですが、なぜそうなったのでしょうか。