native-windows-gui icon indicating copy to clipboard operation
native-windows-gui copied to clipboard

Use alpha channel in ImageList

Open nx10 opened this issue 5 years ago • 2 comments

I have investigated how to use the alpha channel for icons used in ImageList and could solve it partially. (To remove the black icon edges)

It seems like

  • ILC_COLOR32 has to be set on creation (which it already is)
  • LR_CREATEDIBSECTION has to be set when calling LoadImage
  • ImageList_AddMasked should be replaced with ImageList_Add

I have tried setting LR_CREATEDIBSECTION and the alpha channel of BMPs works, PNGs will have a black background and ICOs will work sometimes (love.ico works all other .ico do not)

Maybe the DIB section can be created manually?

Otherwise I would suggest adding a function like

native_windows_gui::ImageList.add_bitmap_from_filename_alpha("some_32bit.bmp")

To enable the use of alpha channel icons.

nx10 avatar Jul 21 '20 14:07 nx10

The DIB section is created manually if the "image-decoder" feature is enabled, and it' is always enabled during the tests. See win32::image_decoder::create_bitmap_from_wic.

If possible I'd like to handle all image loading use case in a single function, but if we can', adding a specific function will be ok.

gabdube avatar Jul 21 '20 15:07 gabdube

I did not see that the DIB section is already created manually. Could it be that the alpha byte just needs to be set to 255? https://stackoverflow.com/questions/18431902/adding-alpha-channel-to-bitmap-or-converting-bitmap-to-32bit

(Can't test this myself at the moment)

nx10 avatar Jul 21 '20 19:07 nx10