Recovering VB6 ImageList images

Jaco

Regular
Joined
Mar 10, 2004
Messages
63
I've upgraded a large VB6 app to VB.NET.
However, the VB6 ImageList doesn't upgrade to the .NET ImageList. That's fine - I'll just dump the same images to a new .NET ImageList. Easier said than done! I don't have the images anymore, just the old VB6 ImageList - how do I extract the images from a VB6 ImageList ?? The ImageList is working in .NET, but I need the images in a new .NET ImageList to associate with other .NET controls.

Here's the code I was trying to use to recover one image as a test, but the second line causes an exception:
Dim test As stdole.IPictureDisp = Me.MyVB6ImageList.ListImages(1).Picture
Dim testimage As System.Drawing.Image = VB6.IPictureDispToImage(test)
testimage.Save("C:\Temp\test", Imaging.ImageFormat.Bmp)

Anyone have any idea how to recover the images?
 
I haven't used VB6 in a while, so I'm not sure, but would it be possible to just throw a few lines in the VB6 program that can loop through the images in the ImageList and save the images to a file?
 
marble_eater said:
I haven't used VB6 in a while, so I'm not sure, but would it be possible to just throw a few lines in the VB6 program that can loop through the images in the ImageList and save the images to a file?

I'm trying to do that in VB.NET since the VB6 ImageList is left in the upgraded project. The code I was attempting to do this with is in the original post. The VB6.IPictureDispToImage method looked promising, but apparently it can't really convert an IPictureDisp to an Image despite it's name - once I have the image in a System.Drawing.Image then I can save it.
 
After some research, it appears that many people have a similar problem with the VB6.IPictureDispToImage function (leading to the "unknown image type" exception). None of the threads I found have any resolution to this.

Any ideas on how to get this function to work?
 
Joy at last !!

For VB6 ImageList images originating from icons, the following code works:
Dim test As stdole.IPictureDisp = Me.MyImageList.ListImages(1).Picture
Dim testicon As System.Drawing.Icon = System.Drawing.Icon.FromHandle(test.Handle)

Apparently that VB6.IPictureDispToImage method doesn't work when the underlying image is an icon - it would have been nice if there were any documentation to that effect!

Thanks anyway to anyone who spent any time thinking about this!
 
Thanks. FWIW here is the C#
C#:
object idx = 1;   
// Image1.Image = VB6.Support.IPictureDispToImage(ImageList1.ListImages.get_Item(ref idx).Picture);
// the above statement throws "unknown image type" exception

stdole.IPictureDisp test = this.ImageList1.ListImages.get_Item(ref idx).Picture;
System.Drawing.Icon testicon = System.Drawing.Icon.FromHandle((IntPtr)test.Handle);
Image1.Image = testicon.ToBitmap();
 
Last edited:
Back
Top