VB.NET ImageList 32bit png alphachannel - How to use them?

Uwe Wiemer 0 Reputation points
2023-06-18T08:29:56.5733333+00:00

Hi,

I am trying to figure out, how to use 32bit png alpha blended images with NET ImageList (in VB.NET). Reason being simply is, I like to use these images in NET controls, such as TabControl and TreeView. Unfortunateley, these controls do require that NET ImageList and nothing else.

The problem is: The alpha channel bits will be transormed into black pixels after the images has been added to the ImageList.

I am working with VS 17.6.3 and NET Framework 4.8.1.

The MSDN docs say, 32bit images cannot be used with ImageList. (why do they offer a PixelFormat.32bitArgb then?) I cannot find any kind of workaround on the internet. I tried CodeProject articels already, I tried stackoverflow already, both to no avail.

It appears to me, that a I have to code my own controls.

Question is: Is there a much simpler workaround? Does NET 7 ImageList offer 32bit png support?

Any help is very much appreciated.

Thanks a lot

Uwe

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,103 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,449 questions
0 comments No comments
{count} votes

12 answers

Sort by: Most helpful
  1. QiYou-MSFT 4,326 Reputation points Microsoft External Staff
    2023-06-19T06:33:17.0966667+00:00

    Hi @Uwe Wiemer

    You can put your images in a file and add them to the appropriate place in your code. For example, in the constructor of /, after calling with code like this: Resources.resxUserControlFormInitializeComponent()

    _imageList.Images.Add(Resources.Image32)
        _imageList.Images.SetKeyName(0, "Image32")
        _myButton.Image = 0
    
    
    

    The following StackOverflow post may be helpful to you:

    ImageList: 32-bit Images lose quality

    Best Regards

    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Uwe Wiemer 0 Reputation points
    2023-06-19T10:12:18.8666667+00:00

    Hi Qi You,

    Thanks for your response, but unfortunately this does NOT solve the problem. I have read the stackoverflow questions and answers already. I have therefore set up several different scenarios in a test app:

    A) Adding images in the designer to NET ImageList

    B) Adding images during runtime from embedded resources to NET ImageList

    C) Adding images during runtime from (project) resources to my own Dictionary of Images.

    I then show all these images in their own PictureBox control. The only pictures, that are displayed correctly, are the ones added to my own Dictionary of Images during runtime (case C)).

    I have set the Project Property to "Use XP Visual Styles" ... and they are used, at least for the button and tabcontrol I have added to the test form.

    What I have not done is an extra resource file - I don't know, how to do that, but I am sure, I will figure it out. BUT, wouldn't that be the same as case B) above?

    Any hint and idea is more than welcome.

    Thanks a lot Uwe


  3. Uwe Wiemer 0 Reputation points
    2023-06-20T08:55:25.0166667+00:00

    Hi Qi You,

    Thanks again for your response. I wonder how all the other users of NET solving this problem? I cannot believe I am the only one coming across this issue.

    Anyway, you wrote a very importat sentence, namely: "...ImageList cannot upload translucent image ofPNG32 ..." In other words, the only workaround is to write my own control ... which is a pity and a lot of work.

    Have you ever heard of MS updating their image list so that it can properly work with those images? I think that even NET is not able to handle alpha channels correctly?!?

    Thanks Qi You

    0 comments No comments

  4. Uwe Wiemer 0 Reputation points
    2023-06-20T08:56:58.5966667+00:00

    Sorry, I certainly meant "..NET 7 is not able to handle ..."

    0 comments No comments

  5. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.