+ Reply to Thread
Results 1 to 3 of 3

Thread: Image losing PropertyItems when adding to ImageList

  1. #1
    xuser is offline VB.NET Forum Newbie xuser is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2009
    Age
    32
    Posts
    2
    Reputation
    0

    Question Image losing PropertyItems when adding to ImageList

    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?

    Code:
    ' il is of type ImageList; img is of type Image.
    MsgBox(img.PropertyItems.Length) ' Length = 68
    il.Images.Add(img)
    MsgBox(il.Images(0).PropertyItems.Length) ' Length = 0
    MsgBox(img.Clone.PropertyItems.Length) ' Length = 68
    il.Images(0) = img.Clone
    MsgBox(il.Images(0).PropertyItems.Length) ' Length = 0

  2. #2
    xuser is offline VB.NET Forum Newbie xuser is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2009
    Age
    32
    Posts
    2
    Reputation
    0

    Default

    I don't get it... This doesn't work either.

    Code:
    For Each origProp As PropertyItem In img.PropertyItems
        il.Images.Item(0).SetPropertyItem(origProp)
    Next
    MsgBox(il.Images(0).PropertyItems.Length) ' Length = 0

  3. #3
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Age
    41
    Posts
    6,907
    Reputation
    670

    Default

    I just ran this code:
    Code:
    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts