Reputation: 1161
Is it possible to display 32-bit images with an alpha channel on a CToolBar control from MFC? At the moment, my toolbar uses a 4-bit image which gets assigned to it by the "Filename" property in Visual Studio 2010.
Thanks in advance!
Upvotes: 5
Views: 3586
Reputation: 21
I had a similar issue. The cause of the issue was the bitmap version. The version required was version 3 bmp v3, bmp wiki. However v3 default to 24 bit depth, which does not include the alpha channels.
I checked the metadata of the bmp file using meatadata2go.com.
Then, I was able to generate a v3 bmp with 32 bits of depth, preserving alpha transparency, by using imagemagick.
The command I used was:
magick convert png_asset_name.png -define bmp3:alpha=on bmp3:new_bmp_asset_name.bmp
Upvotes: 2
Reputation: 648
Late answer, but I had the same problem, so in case someone else is looking for a solution:
32-bit images with 8-bit alpha will work out of the box, at least on XP and newer. You need a BMP file in 32-bit alpha BMP format, which many applications cannot save properly. My approach is to generate PNG images first, and then convert them to 32-bit BMP using this little tool: https://github.com/thomerow/png2bmp32
Once you have such a file, it should be loadable using toolbar.LoadBitmap(...)
without problems.
In case you're using an image list for the toolbar, or if you want to use an image list to display icons in some other control such as a treeview, load the image like this:
CBitmap bitmap;
bitmap.LoadBitmap(...);
imageList.Create(WIDTH_OF_ICONS, HEIGHT_OF_ICONS, ILC_COLOR32, NUMBER_OF_IMAGES, 1);
imageList.Add(&bitmap, RGB(255, 0, 255)); // Color key isn't important.
bitmap.Detach();
Hope this helps!
EDIT: I noticed that the "simple" LoadBitmap()
somehow didn't work in a 64-bit build here. I resorted to using the method of using image lists described above, in combination with toolbar.GetToolBarCtrl().SetImageList(&imageList);
.
Upvotes: 3
Reputation: 2239
You can use 32-bits images with alpha channel using CMFCToolbar instead of CToolbar. This class is in the MFC 2008 Feature Pack (VS2008 SP1) and already included in VS2010. But yoy need to upgrade not just the toolbar but some other things (CWinApp to CWinAppEx, etc.). Have a look at this.
Upvotes: 1