Image losing PropertyItems when adding to ImageList

xuser

New member
Joined
Jul 9, 2009
Messages
2
Programming Experience
5-10
I'm stumped... As soon as an Image with PropertyItems is put into the ImageList, it appears to lose that data. Anyone know why this is happening and how to resolve it?

VB.NET:
[COLOR="SeaGreen"]' il is of type ImageList; img is of type Image.[/COLOR]
MsgBox(img.PropertyItems.Length) [COLOR="SeaGreen"]' Length = 68[/COLOR]
il.Images.Add(img)
MsgBox(il.Images(0).PropertyItems.Length) [COLOR="seagreen"]' Length = 0[/COLOR]
MsgBox(img.Clone.PropertyItems.Length) [COLOR="seagreen"]' Length = 68[/COLOR]
il.Images(0) = img.Clone
MsgBox(il.Images(0).PropertyItems.Length) [COLOR="seagreen"]' Length = 0[/COLOR]
 
I don't get it... This doesn't work either.

VB.NET:
For Each origProp As PropertyItem In img.PropertyItems
    il.Images.Item(0).SetPropertyItem(origProp)
Next
MsgBox(il.Images(0).PropertyItems.Length) [COLOR="SeaGreen"]' Length = 0[/COLOR]
 
I just ran this code:
VB.NET:
Dim img = Image.FromFile(filePath)

Me.ImageList1.Images.Add(img)
MessageBox.Show((img Is Me.ImageList1.Images(0)).ToString)
and got False, i.e. the Image object I added to the ImageList is not the Image stored in the ImageList. A new Image object is created based on the image properties defined by the ImageList. I don't know whether that is always the case but it obviously is in some cases at least. The documentation for the Image.PropertyItems property says:
If the image has no property items or if the image format does not support property items, PropertyItems returns an empty array (that is, an array of length zero).
Presumably the image format supported by your ImageList doesn't support property items.
 
Back
Top