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-21T06:26:25.75+00:00

    Hi @Uwe Wiemer

    I found a way to fix this. I thought the image might need to be processed a bit more, and I solved the problem after clearing the background again.

    Pic4

    Pic1

    Pic3

    This is a 32-bit PNG image before processing.

    Pic2

    I achieved it through the clear picture background color in the PPT. In the same way, you can also do it with other software.

    Similarly, ColorDepth needs to be set to Depth32Bit.

    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-21T20:16:42.1433333+00:00

    Hi Qi You, Wow and thank you very much for your efforts. I am not quite sure about the "... clear picture background color ..." in PowerPoint. What I do know is that you can make a picture colour transparent by just clicking in the Colour Menu in PowerPoint and then clicking into the colour in the image, thus selecting the colour you want to make transparent. Do you mean that, or do I have to click somewhere else? I guess afterwards you save that image again as a png with the PowerPoint menu options, don't you?

    Once I figured that out, I will certainly try this. I have also written a small test proggi and will show you the screenshots, showing you the results of all of my attempts. But first let me try and incooperate your suggestion into that program.

    I'll come back a.s.a.p. Till then, thanks again Uwe


  3. Uwe Wiemer 0 Reputation points
    2023-06-26T15:48:24.7466667+00:00

    Hi @Qi You,

    Thanks again for your effort, I tried this but unfortunately to no avail, as you can see from my screenshot below:

    grafik

    The ones with the square is one that I draw myself with "Greenfish Icon Editor Pro". It is difficult to see, but the very last image in the first line has a gray frame raound it - this frame is originally a blue and and a green line with 125 and 50 alpha value. This image has been drawn, importetd in PowerPoint, made transparent again, saved as PNG and added to the imagelist in the designer AND also added as a Resource in the Project window.

    The very first image in the very last line is the same image, but retrieved from the project resource simply as an image - and all of a sudden it works. The TabControls on the right show, that using the own Image Dictionary and drawing the image on my own in "DrawItem"-event of the TbaControl does also show the correct image.

    I am stuck now ...

    Thanks a lot ... and if you have any further idea I am happy to try it.

    Cheers Uwe

    In other words

    0 comments No comments

  4. Castorix31 89,376 Reputation points
    2023-07-14T09:47:46.5633333+00:00

    If I do a test with a ListView and

     private ImageList myImageListLarge = new ImageList();
     //...
     myImageListLarge.ColorDepth = ColorDepth.Depth32Bit;
    
    

    transparent .png are displayed correctly :

    tUser's image

    0 comments No comments

  5. Uwe Wiemer 0 Reputation points
    2023-07-19T06:41:26.6266667+00:00

    Hi @ Castorix31,

    Thanks a lot for looking into this and coding your own test proggi.

    I've been out, hence my response today and not earlier.

    Well, this is how I created the second row in my own test prog (see screenshot above).

    How did you add the pngs to the newly created ImageList?

    I will, anyway, try the notepad png to add and display and see what happens. I'll keep you posted (even if it takes a while :-))

    Best regards Uwe

    0 comments No comments

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.