wxBitmap transparent background - c++

I have a wxBitmap which can be hidden or revealed on a wxPanel. When the wxBitmap is hidden I would like it to have the background of the wxPanel, instead it has a standard grey background.
To illustrate my point here are two images:
Bitmap shown:
http://i.stack.imgur.com/PzpR9.png
Bitmap hidden:
http://i.stack.imgur.com/GWs7r.png
I tried applying a mask and using alpha channel for transparency, but these do not solve the problem. What I need to do is set the background of the wxBitmap.
Any ideas how I can accomplish this?

I have noticed that if I minimise the window and then show it again, the problem is solved - no default grey background when the bitmap is hidden. I do not know what operation this (minimise + maximise) procedure performs and I have not yet figured out how to implement it programmatically.

Related

Set transparency of an image on openFrameworks

I'm working on openFrameworks and I want to set the transparency of an image in order to modify it when I press a button, but I don't know how to implement this parameter.
In which way can I change this value? Is there a particular function to manage the transparency of an image?
check out http://openframeworks.cc/ofBook/chapters/intro_to_graphics.html
ofEnableAlphaBlending();
ofSetColor(255,0,0,127); # this would be a 50% transparent red color
ofDrawRectangle(20,20,100,100);
ofDisableAlphaBlending();

Using TransparentBlt

I am trying to get my head round using the TransparentBlt function in visual c++ MFC. What I am aiming to achieve is to put one bitmap over the top of the other. The first bitmap is just a standard Stretchblt. The second bitmap is to be placed over the top of the background of the first bitmap. I have made the background of the second bitmap icon pink and I do not want the pink to be visible. Basically I just want to use a function for displaying the icon without showing the pink, how do I do this?
#define TRANSPARENT_MASK RGB(250,84,248)
This is how I have done my the bottom layer bitmaps.
argDC->StretchBlt(WindowRect.left,WindowRect.top,WindowRect.Width(),WindowRect.Height(),
&memDC,0,0,bits.bmWidth-1, bits.bmHeight-1, SRCCOPY);
The last argument of TransparentBlt is crTransparent - the color that should be "transparent". You should specify TRANSPARENT_MASK in your case

win32 c++ owner draw button with transparent image

i've implemented a owner draw button into my win32 app (no MFC). The button is a normal 20x20 bitmap (round icon with transparency). The problem is that the button is positioned on a solid background and i can see the buttons gray background (since the bitmap is round). I've tried responding to WM_CTLCOLORBTN with NULL_BRUSH but no luck.. I've tried displaying the button using a bitmap and a ico file but wont budge.. Does anyone know how to solve this problem?
This is my problem, the settings icon should be transparent at the edges (not white/gray)
It sounds like you're trying to make a non-rectangular control.
You could call SetWindowRgn to tell Windows that your control is non-rectangular.
In addition to what #joel's answer, if you want to make some area transperant put a unique color in the area where you want to have transperancy using some image editors (RGB(0xFF,0x00,0xFF)) is mostly used Then use TransperantBlt
You say it's a solid background but your image shows some kind of orange-yellow gradient as a background. If it really was a standard windows button solid color you can load the bitmap with LoadImage using the LR_LOADMAP3DCOLORS or LR_LOADTRANSPARENT. Since you have a gradient you'll have to use a more complicated technique to mask out the bitmap.
http://www.winprog.org/tutorial/transparency.html

Colored border of the transparent color key around text written on the transparent window

I created a Transparent Layered window with a color key that I use to make the window transparent.
So far it works all fine.
Writing text on it - using GDI+ - works, too...
The problem I encounter is, that the text has a thin border of the colorkey-color around the letters...
What I do in the WM_PAINT is:
1. Clear the drawing area Graphics::Clear(ColorKey);
2. Draw the text on it.
Screenshot of what i mean: http://imageshack.us/photo/my-images/709/cutp.jpg/
Anyone knows about how to avoid this?
Try calling Graphics::SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit).

Adding a transparent bitmap to a windows button

It's a while since I've done this, but I'm trying to add a custom button graphic to a windows button, with some transparent areas. I've tried various schemes but can't seem to get the transparent areas to show. Here's my code:
hbmpUpDisabled = LoadImage(instance,MAKEINTRESOURCE(IDB_UPARROWDISABLED), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS );
SendMessage(GetDlgItem(hWndDlg, IDC_MOVEUP),BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hbmpUpDisabled);
Does anyone notice any problems here? It works if my bitmap is a 1-bit bitmap. I couldn't get a 32 bit bitmap to work, and I'm not sure how to setup a 24 bit or 8 bit bitmap to do it.... I tried a custom 255,0,255 color (which IIRC is a default transparent value), but so far no joy....
LR_LOADMAP3DCOLORS should map grey - in the source image - to to the current button face color. Buttons do not use AlphaBlt or TransparentBlt so there is no way to actually (short of custom painting) set a bitmap with transparent or alpha'd areas onto a button and expect it to work. You just have to pre-prepare the bitmap with the correct button color in its background areas.
That said - I suspect that some of these restrictions may be lifted for buttons implemented by common controls v6. Add commctl 6 as a dependend assembly to your exe and see if the behaviour changes.