[VB.NET] Image from ImageList to PictureBox

Nazgulled

Centurion
Joined
Jun 1, 2004
Messages
119
I have an ImageList with some images, all of them are png with transparency and the transparency is working correctly. The images are somekind of square with a little outline in a transparent background. On the main form, I have a picturebox that will take one of the images in the listbox. The image it will take will be different acording to some arguments, but that doesn't really matter I think.

To apply the pictures I do something like this:

frmMain.pic1Enabled.Image = frmMain.imgLabels.Images.Item(0)

The problem is that the image does not have the correct colors I designed in the first place. The outline is somewhat blue where it should be gray. The rectangle background is also a little blueish...
 
Try setting the ImageList's ColorDepth property. By default it is 8 bits per pixel, which is just, well, silly, because it makes gradients, detailed color, and alpha transparency look all kinds of bad. You may or may not have to remove the images from the ImageList and then reload them (after you change the ColorDepth) in order for them to appear correctly.
 
That is not the problem, the first thing I did when creating the imagelist was setting it to "Depth32Bit" otherwise the PNG transparency wouldn't work...
 
Then I can't think of a reason why this shouldn't work. Have you tried reloading the images into the ImageList? Is the ImageList populated at run-time or design-time? Maybe you ought to post the code that populates the ImageList and the code that takes the image from the ImageList and shows it in the PictureBox.
 
The ImageList is populated at design-time and the code that takes the image from the ImageList and shows it in the PictureBox is already in the first post.

For the generated designer code, check this file:
http://stuff.nazgulled.net/code/vb.net/FormProfilesManager.Designer.vb

The ImageList control is called imgLabels and the PictureBox controls that will take images from it are named pic1Enabled, pic2Enabled, pic1DHCP and pic2DHCP.
 
Nevermind, I kinda fixed it. Instead of using an ImageList, I add all images to the resources file and used My.Resources. Now the colors work correctly.
 
Try setting the ImageList's ColorDepth property. By default it is 8 bits per pixel, which is just, well, silly, because it makes gradients, detailed color, and alpha transparency look all kinds of bad. You may or may not have to remove the images from the ImageList and then reload them (after you change the ColorDepth) in order for them to appear correctly.


I was having the same problem and bumped into this forum. If the clarity of your picture is not working properly when retreiving the image from an imageList and transferring to a picturebox, it's most likely because you must change the ColorDepth property first. Then, you reload your images into the imageList collection, manually, like you did when you set up the collection.

Thanks snarfblam for providing the correct path to take when having the issue this forum was set up for.:D
 
Back
Top