Visual Studio 2010 - C++ MFC application with Ribbon UI - Transparency in bitmaps - visual-studio-2010

I am playing around with a small MFC-wizard-generated application, in Visual C++ 2010, and I just decided to put my own bitmap into the resources to replace the three-cubes MFC bitmap that shows up in the ribbon UI Application Button, aka the "marble".
The original appeared to use black (0,0,0) as a transparency color, but I am unable to determine what the MFC Ribbon (mfc-feature-pack stuff) stuff in Visual Studio 2010 does to determine transparency on a bitmap used as the ribbon's main icon.
The properties of the ribbon (IDR_RIBBON) show Image=IDB_MAIN, and IDB_MAIN is a 32x32 bitmap in BMP format, loaded from a disk file called main.bmp.
Some of the bitmap resources in this project have what looks like what I would expect: A magenta color which becomes transparent, but the MFC main bitmap did not use this color scheme or palette.
Here is an example of the actual results, which are I hope show that the results are not what I wanted:
Incidentally, It does not seem possible to use an ICON resource in the Application Button, so I am a little mystified how they pull off the transparency in it.

You need to create a 32-bit bitmap that has an alpha channel for transparency. The method by which I've done this is not very straightforward but it was the only thing I could come up with.
Use Paint.Net to convert your source image into a PNG that preserves the transparency. Unfortunately Paint.Net does not support creating 32-bit bitmaps directly.
Then download AlphaConv which can create the 32-bit bitmap from the PNG file.

Translucent PNG, perhaps? Did you know that BMP files can also have alpha channels?

Related

Why do standard applications show slightliy different colors

I uploaded a simple png file with a overall fill color here: https://ufile.io/kx1mopq2
If i view this file in the windows explorer or in firefox the color displayed is slightly different than the color shown in Windows Paint, Paint 3d or several other applications i tested - including WinApi and Qt applications i developed myself.
In the screenshot below on the left you see firefox and windows explorer preview - we think that this display color is the correct one. On the right you see Pant and paint 3d. I modified the file in paint as i moved a strip from the left views into the right views in order to make the difference visible.
My question is: Where do these differences have their origin? I want my applications to show the same color as FireFox or Windows Explorer. It seems that there is a application setting or the like that influences that?
Any suggestion welcome.

XP Popup Menu Icons not Transparent when highlighted

I know XP is old, but I just have to know the issue here.
I don't see a way to provide a popup menu with anything like an icon or bitmap with a mask, only a bitmap. So, if I use a compatible bitmap, it will look transparent when the selection bar is not highlighting it, but when highlighted the entire graphic still shows (with a square button face color around it).
If I use a 32bit DIB with alpha, the transparent item just shows black (whereas Windows 10 handles the transparency fine - I presume Vista and Win7 would, too).
If I manually set all the A's to 0 in the DIB, it is still black (on Win10, the images where color would normally be appear white - I would have thought it would be transparent).
Anyway, was there ever a way to provide an icon (since it has a mask), or a bitmap with mask, to a menu so things like XP can handle it automatically (no owner draw)?
Is there a way to force loading of an .ICO file to be the 256 color version instead of the 32bit RGB/A version? I don't have a 24bit RGB graphic in the .ICO, so maybe XP would pick that if it existed instead?
I know GDI doesn't support alpha in all cases, but sometimes it does, and it appears the Windows version matters as well.
Does someone have a background on this, and can tell if this is a known XP issue with 32bit bitmaps?
On XP you must custom draw but not the entire thing, just the bitmap/icon.
On Windows 95/NT4 the only way to do this properly is to custom draw the entire menu item. Before Vista the menu look only changed once, the addition of flat menus in XP, so custom draw everything is certainly possible.
Some time around Windows 98/2000 the ability to set MENUITEMINFO.hbmpItem to HBMMENU_CALLBACK was added. Use DrawIconEx or a image list.
Vista added support for 32bit ARGB bitmaps. You should not use the callback method here because that will disable the new visual style.
See also:
Themed menu’s icons, a complete Vista and XP solution
MSJ cool custom draw

UWP package.appmanifest Asset generator scales up my image

I am trying to create the visual assets for a UWP Windows 10 app. Using VS 2017 (15.2, 26430.6) and the package.appmanifest. When I place a 400x400 .png image into the asset generator, the size it recommends, it is scaling it up to 533x533 automatically, which is causing distortion and artifacts. The prompt does not support SVG (though it does support other vector graphic formats, namely .pdf and .ai).
In case it matters, I originally placed a 327x327 (which I thought might have been the source of the scaling). But I have since closed my solution and reopened and the scaling is still there.
Edit: Created blank new app. Placed same 400x400 image in Asset Generator and it still scales to 533x533
I have tested Asset Generator according to your description. But I can not reproduce your issue. It seems that there is some issue with the Asset Generator you create the visual assets with.
When I place a 400x400 .png image into the asset generator, the size it recommends, it is scaling it up to 533x533 automatically, which is causing distortion and artifacts. The prompt does not support SVG (though it does support other vector graphic formats, namely .pdf and .ai).
If you want to use svg file to avoid scaling problems. You could use The UWP Visual Assets Generator tool of Visual Studio. And it can create all the visual assets needed for an UWP app. You can also choose the width of your icon within the asset.
For more detail please refer to UWP Visual Assets Generator.

Using CxImage in VC++ 2008 MDI application

Im new to cximage so i need help. Im building as MDI project in which i need cximage functionalities.
Please help me by specifying how to load and display an image in the child window.
How to get active windows hwnd and hdc.
this is the requirement:
Drawing App(Image Viewer and editing) using cximage and Mdi
First of all, there should be a provision to open an image (any format i.e. tif, jpg, bmp…..).
The user should be able to do operations like rotate, zoom negate etc. The changes should be saved after prompting.
The user should be able to draw standard shapes like rectangle, square etc on top of the image.
Should be able to fill color in the shapes drawn. Save that as well.
Also user should be given a provision to change an image format(i.e. may be from jpg to tif and so on) and save.
http://www.codeproject.com/Articles/1300/CxImage itself is a good tutorial and it has sample project as well.
see the tutorial below to which explains how to get active windows handle in MDI app:
http://www.winprog.org/tutorial/app_four.html

Transparent PNG file in a Pure C++/Win32 Application

I have a pure C++/Win32 VS2005 desktop application. During my WM_PAINT response, when I paint my window, I'd like to be able to Project a transparent PNG image onto my Window.
any pointer will be appreciated.
GdiPlus has been part of Windows since Windows XP at least, and can decode JPEG, PNG and GIF files with ease.
A newer API for dealing with image files is the Windows Image Component. One of the samples covers using WIC to decode an image and GdiPlus to perform the alpha aware painting.
The Windows Imaging Component (WIC) is the primary API for native code that provides the ability to encode and decode various image formats. You can use it to load a PNG image into your application.
http://msdn.microsoft.com/library/ee719902
Alternatively you can use GDI+ but that’s pretty old technology and doesn’t work nearly as well. You can also use GDI+ to render the image but I suggest Direct2D.
Direct2D is capable of rendering a WIC bitmap directly on the GPU or in software via a window or bitmap device context.
Here’s an introductory article on Direct2D:
http://msdn.microsoft.com/en-ca/magazine/dd861344.aspx
And this one describes how to use Direct2D with WIC:
http://msdn.microsoft.com/en-us/magazine/ee819134.aspx

Resources