是的,它会复制。请注意下面的 CreateBitMap 调用。因此,为了尽可能降低资源使用率,您应该取消注释您的 dispose 行。
private int Add(ImageList.Original original, ImageList.ImageCollection.ImageInfo imageInfo)
{
if (original == null || original.image == null)
throw new ArgumentNullException("value");
int num = -1;
if (original.image is Bitmap)
{
if (this.owner.originals != null)
num = this.owner.originals.Add((object) original);
if (this.owner.HandleCreated)
{
bool ownsBitmap = false;
Bitmap bitmap = this.owner.CreateBitmap(original, out ownsBitmap);
num = this.owner.AddToHandle(original, bitmap);
if (ownsBitmap)
bitmap.Dispose();
}
}
else
{
if (!(original.image is Icon))
throw new ArgumentException(System.Windows.Forms.SR.GetString("ImageListBitmap"));
if (this.owner.originals != null)
num = this.owner.originals.Add((object) original);
if (this.owner.HandleCreated)
num = this.owner.AddIconToHandle(original, (Icon) original.image);
}
if ((original.options & ImageList.OriginalOptions.ImageStrip) != ImageList.OriginalOptions.Default)
{
for (int index = 0; index < original.nImages; ++index)
this.imageInfoCollection.Add((object) new ImageList.ImageCollection.ImageInfo());
}
else
{
if (imageInfo == null)
imageInfo = new ImageList.ImageCollection.ImageInfo();
this.imageInfoCollection.Add((object) imageInfo);
}
if (!this.owner.inAddRange)
this.owner.OnChangeHandle(new EventArgs());
return num;
}
当 ImageList 释放时,它释放所有图像的副本。再说一遍,是的,除了取消注释您的其他处置行之外,在表单关闭时处置它是正确的。
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.originals != null)
{
foreach (ImageList.Original original in (IEnumerable) this.originals)
{
if ((original.options & ImageList.OriginalOptions.OwnsImage) != ImageList.OriginalOptions.Default)
((IDisposable) original.image).Dispose();
}
}
this.DestroyHandle();
}
base.Dispose(disposing);
}