Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Alpha channel and ImageList?

  1. #1

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Resolved [RESOLVED] [2005] Alpha channel and ImageList?

    Hello everyone,

    I would like to store some icons inside my application (so no extra files are needed to run the app), so I used an ImageList, but this seems to screw up the alpha channel of the icons.

    I have a form with a StatusStrip control on it. In this strip is a StatusLabel with an image next to it. When I load an icon with alpha channel directly from file to set as it's image it displays fine, but when I load the same icon into an ImageList and set it as the StatusLabel's image, all pixels that have an alpha other than 0% or 100% are displayed as blue.

    Changing the ImageList's ColorDepth value does not solve this problem.

    I would really like the icons to display correctly.

    Thanks for any help.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Alpha channel and ImageList?

    ImageLists don't store icons. If you add an icon the image format will be changed. Just go to the Resources tab of the project properties and add the icon as a genuine Icon resource. If you name it MyIconResource you would then retrieve it as an Icon object as My.Resources.MyIconResource. Having said that, ToolStripStatusLabels don't display icons either. They will also change your image format but not in the same way as an ImageList. I'm not sure of all the technicalities mind you, but that's the bones of it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Alpha channel and ImageList?

    I have seen it indicated that its a bug that the alpha channel is lost when adding images to an image list.

    You are better off making a resource file and embedding the images in that, and extracting them for use at runtime, they should keep their alpha channel that way

  4. #4

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [2005] Alpha channel and ImageList?

    I have now added the icons to my resources and it works fine.

    But I have one more question: how to set an image from the resources through code?

    I can change it within VB itself, simply by changing the image-property. But I don't know what to do code-wise to make this happen...
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Alpha channel and ImageList?

    use the My namespace.. for example, lets say one of your resource images was a car (and you named it car in the resource file)

    you would just do
    VB Code:
    1. MyStatusStrip.BackgroundImage = My.Resources.Car

  6. #6

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: [RESOLVED] [2005] Alpha channel and ImageList?

    Thanks, works like a charm!
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] Alpha channel and ImageList?

    yeah, you gotta love the My namespace.. back in .net 2003, you would have to use a few lines of reflection code to extract the image from the exe and use it at runtime

Posting Permissions

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



Click Here to Expand Forum to Full Width