1

I am really confused here ...

I am trying to add a MFC Button control onto my dialog in the IDE.

I want it to just show a BMP file. I have another already on the dialog that shows with a transparent background.

This is the image for the good button:

Good Transparency

This is the other button image I downloaded. But it is PNG:

New image PNG

I have tried to convert it so that it is 32 bit BMP so that it is transparent:

New image BMP

But it is failing. It shows with a black background:

Results

You can see on that screenshot that the lower image shows OK. But not the new one. How do I fix this image file?

Update:

I used a different image in the end for the question mark. But for others I ended up using PNG and manually using the load method as outlined below:

enter image description here

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • For some reason the images are not showing correctly in the question. – Andrew Truckle Nov 21 '16 at 21:05
  • Has it been saved correctly? http://stackoverflow.com/a/29585717/59303 – ChrisF Nov 21 '16 at 21:17
  • 1
    How did you convert the png to bmp ? It doesn't work with Paint. But it does with Gimp. – Jabberwocky Nov 22 '16 at 09:39
  • I used paint. I will try Gimp. Anything else I need to know to make work? Just save PNG as BMP? Will try tonight – Andrew Truckle Nov 22 '16 at 12:32
  • I remember I had to downgrade Gimp to 2.6 version because newer versions saved the BMP file differently! – sergiol Nov 22 '16 at 12:54
  • @sergiol Good to know, I'm using 2.6.12 and it works fine. Just amazing that BMP supports transparency but MSPaint doesn't. – Jabberwocky Nov 22 '16 at 13:57
  • You don't need to convert the image to a BMP in order to use it on the dialog. I've done what you've asked and used the PNG image as is. – rrirower Nov 22 '16 at 14:14
  • I was meaning 2.6.0! – sergiol Nov 22 '16 at 14:55
  • @rrirower How? When I select a MFCButton and set the type it must be Bitmap or Icon and it only lists my Bitmaps and none of my PNG resources. – Andrew Truckle Nov 22 '16 at 16:34
  • You can use GDI+ and the PNG image to craft your own Button class. That would negate the need to convert the image to a BMP and you would not need to use CMFCButton. – rrirower Nov 22 '16 at 16:39
  • rrirower That may be, but the point it, I should be able to do it. I have another MFC Button on the same dialogue with a transparent BMP. I am struggling with GIMP. @sergiol Can you guys confirm the advanced settings to use? Thanks. – Andrew Truckle Nov 22 '16 at 17:01
  • 1
    I don't have that computer anymore, but one thing I remember that made confusion was the format. Don't take my advice for sure, but if I recall it correctly, on the https://hostr.co/files/QCtMjXp/Export%20Image%20as%20BMP.png dialog I had to select `A8 R8 G8 B8` on the `32 bit` section. – sergiol Nov 22 '16 at 20:11
  • BTW, once ago I did http://stackoverflow.com/a/22875225/383779 to make use of images on `CMFCButton` controls. – sergiol Nov 22 '16 at 20:16
  • 1
    I confirmed now I used the code I linked on my previous comment to load PNG images using `HBITMAP hbmp;` `hbmp =::MyButtonLoadBitmap(IDB_OK);` `m_btnOK.SetBitmap(hbmp);` – sergiol Nov 24 '16 at 14:00
  • 1
    BTW, You may have to Pre-Multiply alpha values because I don't know if it uses the `AlphaBlend ` function on behind. So refer to https://msdn.microsoft.com/en-us/library/dd183393%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 and read CAREFULLY the `AlphaFormat`parameter explanation. So, I will put code on next comment as it does not fit here. – sergiol Nov 24 '16 at 14:10
  • 1
    `for (int y=0; y – sergiol Nov 24 '16 at 14:10
  • 1
    Or you will have to do http://forums.codeguru.com/showthread.php?420631-setting-CImage-alpha-values&p=1560260#post1560260 which does the pre-multiplication, but also adds 127. I did not fully understood why the + 127 , but this post was the "savior of the motherland" for me when I had a problem doing `AlphaBlend` of PNG images where image lines where appearing incorrectly. – sergiol Nov 24 '16 at 14:15
  • @sergiol I used the `MyButtonLoadBitmap` ... :) – Andrew Truckle Nov 29 '16 at 18:49
  • Can you post here please a capture to see if your image is presenting well itself? – sergiol Nov 29 '16 at 20:04
  • @sergiol I tried another image and for some reason it shows a black edge to the image when the source does not have it. I see your comments about AlphaFormat but they are a bit over my head. – Andrew Truckle Nov 30 '16 at 14:33
  • @AndrewTruckle: See my question and my own answer on http://stackoverflow.com/questions/43183799/mfc-cimage-alpha-blending-gone-wrong – sergiol Apr 03 '17 at 11:54

0 Answers0