-
MFC : CBitmapButton with a transparant color
Hi,
I use pictures instead of CButton with this component : http://www.codeguru.com/Cpp/controls...cle.php/c5163/
But I need to add a transparant color, I wanted to use this code : http://www.codeguru.com/forum/showthread.php?p=1025767
But it's not to MFC,
Does someone have a solution to modify the component I gave above ?
Thanks all.
-
Re: MFC : Make a bitmap with a transparant color
I've just been working on this myself. You need to nominate a particular colour in the bitmap to be the "transparency colour". In my case, I chose 100% green and I used this code which I modified from some code I found on MSDN....
In your class - or header file...
Code:
const COLORREF RGB_BLACK = 0x00000000L;
const COLORREF RGB_WHITE = 0x00FFFFFFL;
const COLORREF RGB_RED = 0x000000FFL;
const COLORREF RGB_GREEN = 0x0000FF00L;
const COLORREF RGB_BLUE = 0x00FF0000L;
const COLORREF RGB_LIGHTGRAY = 0x00C0C0C0L;
// Define any others you need.
// The colour inside this button's bitmap(s) that should be regarded as transparent
COLORREF m_kTransparentColour;
// The thresholds for red, green & blue
short m_RedThreshold, m_GreenThreshold , m_BlueThreshold;
In your CPP file...
Code:
// Initialise the transparency colour
// and thresholds for this button.
m_kTransparentColour = RGB_GREEN;
m_RedThreshold = 100; // Adjust to your own requirements
m_GreenThreshold = 132; // Adjust to your own requirements
m_BlueThreshold = 80; // Adjust to your own requirements
The actual code....
Code:
void YourClass::DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF kTransparentColour, bool bAssume100Green)
{
BITMAP bm;
COLORREF cColour;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;
int x, y;
hdcTemp = CreateCompatibleDC(hdc);
if (HGDIOBJ hOldObj = SelectObject(hdcTemp, hBitmap)) // Select the bitmap
DeleteObject(hOldObj);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device
// to logical points
// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);
// Create a bitmap for each DC. DCs are required for a number of GDI functions.
// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));
// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
// If we're assuming a 100% green background (the normal case) set all
// pixels that are green or "very nearly green" to be exactly 100% green.
if (bAssume100Green)
{
for (x = 0; x < ptSize.x; x++)
for (y = 0; y < ptSize.y; y++)
{
COLORREF pixel = GetPixel(hdcTemp, x, y);
if (pixel)
{
DWORD dwRedContent, dwGreenContent, dwBlueContent;
dwRedContent = ((pixel & 0x000000FF) % 0xFFFFFF);
dwGreenContent = (((pixel & 0x0000FF00) >> 8) % 0xFFFFFF);
dwBlueContent = (((pixel & 0x00FF0000) >> 16) % 0xFFFFFF);
// Does the pixel have a high content of green?
if ((short)dwGreenContent > m_GreenThreshold)
{
// If so, and it has a low content of both
// red and blue, set it to be 100% green.
if (((short)dwRedContent < m_RedThreshold) &&
((short)dwBlueContent < m_BlueThreshold))
SetPixel(hdcTemp, x, y, RGB_GREEN);
}
}
}
}
else
cColour = SetBkColor(hdcTemp, kTransparentColour);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
// Now, if we're assuming a 100% green background, make
// absolutely sure that any 100% green pixels are converted
// to white in the mask - and all other pixels are black.
if (bAssume100Green)
{
for (x = 0; x < ptSize.x; x++)
for (y = 0; y < ptSize.y; y++)
{
COLORREF pixel = GetPixel(hdcTemp, x, y);
if (pixel == RGB_GREEN)
SetPixel(hdcObject, x, y, RGB_WHITE);
else
SetPixel(hdcObject, x, y, RGB_BLACK);
}
// Now change the green background colour for the supplied
// bitmap to be the colour that we want for transparency.
for (x = 0; x < ptSize.x; x++)
for (y = 0; y < ptSize.y; y++)
{
COLORREF pixel = GetPixel(hdcTemp, x, y);
if (pixel)
if (pixel == RGB_GREEN)
SetPixel(hdcTemp, x, y, kTransparentColour);
}
}
else
SetBkColor(hdcTemp, cColour);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
// Copy the background of the main DC to the destination.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY);
// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
// Mask out the transparent coloured pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.
BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));
// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
The main bit I added was support for "assume 100% green". All this does is to look at colours that are "almost 100% green" and turn them into precisely 100% green. If you use a different colour, you'll need to adjust m_kTransparentColour (and the RGB thresholds) to suit your own requirements. It takes quite a long time to get this right BTW – so be prepared to experiment…! :wave:
[Edit...] Incidentally, the parameters xStart and yStart will both be 0 in most cases.
-
Re: MFC : Make a bitmap with a transparant color
As an alternative, take a look at CDC::TransparentBlt().
-
Re: MFC : Make a bitmap with a transparant color
And what about CBitmapButton ?
I finally choose using this component, it really easier to use !
Is it possible making it transparent ?
-
Re: MFC : Make a bitmap with a transparant color
Yes - use the code that I gave you above. That's exactly what I was doing... :) You need to call it in DrawItem() and OnPaint() - selecting the appropriate bitmap to pass to the DrawTransparentBitmap() function.
The main problem is that you have to nominate a particular colour as the transparency colour. This sounds very easy in theory - but in practice, most graphics packages (DrawPlus / Paint / PhotoShop etc) don't export the exact colours that you define. In my case, 100% green would come out as "not quite" 100% green - so I needed to correct this in the source bitmap. However, it is possible. I managed to make it work extremely well.
-
Re: MFC : Make a bitmap with a transparant color
Must I declare transparent color I want ?
Isn't it possible getting the transparent of a pixel given ? (by it's X, Y position) ?
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by FireJocker
Must I declare transparent color I want ?
Yes....
Quote:
Originally Posted by FireJocker
Isn't it possible getting the transparent of a pixel given ? (by it's X, Y position) ?
Not as far as I know - though someone might correct me about that.
-
Re: MFC : Make a bitmap with a transparant color
lol !
I'm really bad ! :) I don't see how using your code
Code:
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CBitmapButton::DrawItem(lpDIS);
DrawTransparentBitmap(
}
what are these parameters :
HDC hdc, HBITMAP hBitmap, short xStart, short yStart, bool bAssume100Green ?
Sorry being so bad !
-
Re: MFC : Make a bitmap with a transparant color
Okay, sorry - here's how to call the function....
Code:
// From 'OnPaint()
void CTransparentBitmapButton::OnPaint()
{
if ((GetParent()) && (GetParent()->IsIconic()))
{
CBitmapButton::OnPaint();
}
else
{
CPaintDC dc(this); // device context for painting
// At least onw bitmap must be loaded before calling 'Paint()'
ASSERT(m_bitmap.m_hObject != NULL);
// and we'll assume until we find otherwise, that
// the button is being drawn in its normal state.
CBitmap* pBitmap = &m_bitmap;
if ((!(IsWindowEnabled())) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(dc.m_hDC, *pBitmap, 0, 0, m_kTransparentColour, true);
}
}
// From 'DrawItem()'
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
// At least onw bitmap must be loaded before calling 'DrawItem()'
ASSERT(m_bitmap.m_hObject != NULL);
CBitmap* pBitmap = &m_bitmap;
UINT state = lpDrawItemStruct->itemState;
if ((state & ODS_SELECTED) && (NULL != m_bitmapSel.m_hObject))
pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && (NULL != m_bitmapFocus.m_hObject))
pBitmap = &m_bitmapFocus;
else if ((state & ODS_DISABLED) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(lpDrawItemStruct->hDC, *pBitmap, 0, 0, m_kTransparentColour, true);
}
I'll be out for the next couple of hours - but leave a message saying how you got on.
-
Re: MFC : Make a bitmap with a transparant color
ok, thanks :)
I was near your code ! :)
Looking the code of CBitmapButton in afxext.h then in winbtn.cpp, my code was .....
Code:
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CBitmapButton::DrawItem(lpDIS);
HBITMAP pBitmap = m_bitmap;
UINT state = lpDIS->itemState;
if ((state & ODS_SELECTED) && m_bitmapSel.m_hObject != NULL)
pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && m_bitmapFocus.m_hObject != NULL)
pBitmap = &m_bitmapFocus; // third image for focused
else if ((state & ODS_DISABLED) && m_bitmapDisabled.m_hObject != NULL)
pBitmap = &m_bitmapDisabled; // last image for disabled
DrawTransparentBitmap(lpDIS->hDC, pBitmap,
}
I'll use yours then I'll answers you.
thanks a lot for your help !
-
Re: MFC : Make a bitmap with a transparant color
First Set your Button Style OwnerDraw.Then use CBitMapButton Class and Create Object of your CBitmap Class Associate them with your Dialog Control and now do what ever u want
some few lines will helps you
Code:
CBitmapButton m_btnAdd;
DDX_Control(pDX, IDC_BUTTON_UPDATE, m_btnAdd);
//now load the state of your button
m_btnAdd.LoadBitmaps(IDB_ADD_NORMAL, IDB_ADD_PRESSED, IDB_ADD_FOCUSED, IDB_ADD_DISABLED);
m_btnAdd.SizeToContent();
that is enough for your code.
Thanx.:thumb:
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by humptydumpty
First Set your Button Style OwnerDraw.Then use CBitMapButton Class and Create Object of your CBitmap Class Associate them with your Dialog Control and now do what ever u want
some few lines will helps you
Code:
CBitmapButton m_btnAdd;
DDX_Control(pDX, IDC_BUTTON_UPDATE, m_btnAdd);
//now load the state of your button
m_btnAdd.LoadBitmaps(IDB_ADD_NORMAL, IDB_ADD_PRESSED, IDB_ADD_FOCUSED, IDB_ADD_DISABLED);
m_btnAdd.SizeToContent();
that is enough for your code.
Thanx.:thumb:
I don't see how your code help me making a CBitmapButton transparent
Could you explain ... ?
thx
-
Re: MFC : Make a bitmap with a transparant color
Just Tryied That Once and let me know.Don't Forget to use CBitmapClass
-
Re: MFC : Make a bitmap with a transparant color
@ John E
------------
Ok, If I understand a little, your code allow some threshold to make the transparency, I'm simply using one colour to make transparency, I think I'll remove this possibility,
but, when I modify by calling your function with the parameter bAssume100Green to "false" transparency seems working :)
I successfully get the Dialog Background, the originally but not the one I put with this code :
Code:
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
CBitmap Bitmap;
CDC MemDC;
Bitmap.LoadBitmap(p_iIDD_Background); // lecture bitmap dans les ressources
BITMAP InfosBmp; // structure d'informations.
Bitmap.GetBitmap(&InfosBmp);
MemDC.CreateCompatibleDC(pDC); // creation d'un DC en memoire
MemDC.SelectObject(&Bitmap); // selection du bitmap dans le DC en memoire
// transfert final du bitmap dans le dc de la view.
pDC->BitBlt( 0,0,InfosBmp.bmWidth, InfosBmp.bmHeight,
&MemDC,
0,0,
SRCCOPY);
return TRUE;
}
How merge the tranparency with this background ?
-
Re: MFC : Make a bitmap with a transparant color
There is already a TransparentBlt function.
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by thomas_nibu
There is already a TransparentBlt function.
how using it ?
-
Re: MFC : Make a bitmap with a transparant color
You can search Code project or Code guru to find out.
www.codeproject.com
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by thomas_nibu
Searching http://www.codeproject.com/info/sear...d=2%2F7%2F2006
just give 6 result which dosn't help me using this function,
an idea ? an advice ?
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by humptydumpty
Just Tryied That Once and let me know.Don't Forget to use CBitmapClass
There isn't any change with your code
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by John E
Not as far as I know - though someone might correct me about that.
In fact, yes I modified your code to get the color of a given pixel to make the transparancy
Code:
#pragma once
#include "afxext.h"
class CTransparentBitmapButton :
public CBitmapButton
{
private:
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap);
// The colour inside this button's bitmap(s) that should be regarded as transparent
// is selected by the one of the pixel locate by X, Y
int m_iXPxlTranparent, m_iYPxlTranparent;
public:
CTransparentBitmapButton(int XPxlT,int YPxlT);
~CTransparentBitmapButton(void);
virtual void OnPaint();
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
#include "StdAfx.h"
#include ".\transparentbitmapbutton.h"
CTransparentBitmapButton::CTransparentBitmapButton(int XPxlT,int YPxlT)
{
// Initialise the transparent pixel X,Y
m_iXPxlTranparent = XPxlT;
m_iYPxlTranparent = YPxlT;
}
CTransparentBitmapButton::~CTransparentBitmapButton(void)
{
}
// From 'OnPaint()
void CTransparentBitmapButton::OnPaint()
{
if ((GetParent()) && (GetParent()->IsIconic()))
{
CBitmapButton::OnPaint();
}
else
{
CPaintDC dc(this); // device context for painting
// At least onw bitmap must be loaded before calling 'Paint()'
ASSERT(m_bitmap.m_hObject != NULL);
// and we'll assume until we find otherwise, that
// the button is being drawn in its normal state.
CBitmap* pBitmap = &m_bitmap;
if ((!(IsWindowEnabled())) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(dc.m_hDC, *pBitmap);
}
}
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
// At least onw bitmap must be loaded before calling 'DrawItem()'
ASSERT(m_bitmap.m_hObject != NULL);
CBitmap* pBitmap = &m_bitmap;
UINT state = lpDrawItemStruct->itemState;
if ((state & ODS_SELECTED) && (NULL != m_bitmapSel.m_hObject))
pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && (NULL != m_bitmapFocus.m_hObject))
pBitmap = &m_bitmapFocus;
else if ((state & ODS_DISABLED) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(lpDrawItemStruct->hDC, *pBitmap);
}
void CTransparentBitmapButton::DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap)
{
BITMAP bm;
COLORREF cColour;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;
hdcTemp = CreateCompatibleDC(hdc);
if (HGDIOBJ hOldObj = SelectObject(hdcTemp, hBitmap)) // Select the bitmap
DeleteObject(hOldObj);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device
// to logical points
// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);
// Create a bitmap for each DC. DCs are required for a number of GDI functions.
// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));
// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
COLORREF transparentColour = GetPixel(hdcTemp, m_iXPxlTranparent, m_iYPxlTranparent);
if (transparentColour) cColour = SetBkColor(hdcTemp, transparentColour);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
SetBkColor(hdcTemp, cColour);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
// Copy the background of the main DC to the destination.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);
// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
// Mask out the transparent coloured pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.
BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));
// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
But as I tell you before this post, I got the grey of the CDialog classic instead of the color of the bitmap I draw on the CDialog with this code :
Code:
BOOL CDigiDialog::OnEraseBkgnd(CDC* pDC)
{
CBitmap Bitmap;
CDC MemDC;
Bitmap.LoadBitmap(p_iIDD_Background); // lecture bitmap dans les ressources
BITMAP InfosBmp; // structure d'informations.
Bitmap.GetBitmap(&InfosBmp);
MemDC.CreateCompatibleDC(pDC); // creation d'un DC en memoire
MemDC.SelectObject(&Bitmap); // selection du bitmap dans le DC en memoire
// transfert final du bitmap dans le dc de la view.
pDC->BitBlt( 0,0,InfosBmp.bmWidth, InfosBmp.bmHeight,
&MemDC,
0,0,
SRCCOPY);
return TRUE;
}
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by FireJocker
@ John E
------------
[...]
when I modify by calling your function with the parameter bAssume100Green to "false" transparency seems working :)
Yes - the transparency will work regardless of that setting. What the setting does is this....
If a colour is found which has a high percentage of green but a low percentage of the other colours, it is assumed to be 100% green (in other words, anything that is "close" to 100% will be assumed to be exact).
Another way of putting this is to say, "if the image contains any 'bright' green, assume that it was intended to be 100% green."
-
Re: MFC : Make a bitmap with a transparant color
@John E :
In your code, where is get pixel color which replace the transparent one ?
[EDIT]
I tried to patch with the following code to test, but instead of getting right pixel I got black one where pixel might be transparent (nb: IDB_BITMAP1 is my CDialog background)
Code:
//************************************************************
// Copy the background of the main DC to the destination.
//BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);
CBitmap Bitmap;
HDC MemDC;
Bitmap.LoadBitmap(IDB_BITMAP1); // lecture bitmap dans les ressources
BITMAP InfosBmp; // structure d'informations.
Bitmap.GetBitmap(&InfosBmp);
MemDC = CreateCompatibleDC(hdc); // creation d'un DC en memoire
if (MemDC)
{
SelectObject(MemDC, &Bitmap); // selection du bitmap dans le DC en memoire
// transfert final du bitmap dans le dc de la view.
BitBlt(hdcMem, 0,0,InfosBmp.bmWidth, InfosBmp.bmHeight, MemDC, 0,0, SRCCOPY);
DeleteDC(MemDC);
}
//************************************************************
What do you think about this new problem ?
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by FireJocker
@John E :
In your code, where is get pixel color which replace the transparent one ?
In my original code, that colour is passed as a parameter to "DrawTransparentButmap(...) - i.e.
Code:
DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF kTransparentColour, bool bAssume100Green);
However, I noticed that you've removed that parameter in your implementation. In fact, I can't tell from your code whether you're using a different strategy so I can't guess at what you're doing wrong. However, my code does work. I'm using it myself.
-
Re: MFC : Make a bitmap with a transparant color
I know your code run,
I just modify it to get the color of a pixel given by X,Y :
Code:
COLORREF transparentColour = GetPixel(hdcTemp, m_iXPxlTranparent, m_iYPxlTranparent);
if (transparentColour) cColour = SetBkColor(hdcTemp, transparentColour);
it's the only change I do (after removing thresholds possibility)
I try to get as background a picture given by IDB_BITMAP1 (in resource)
So i'm trying to understand how to use it in all the DC moves
I succefully load it but where to put it in your code
Now I'm trying to put it in the mask
but I'm not really good with the DC
I think I have to put it near :
Code:
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
What do you think about it ?
-
Re: MFC : Make a bitmap with a transparant color
After creating the object mask (and before creating the inverse of the object mask) you need to set the background colour back to its original colour - e.g.
Code:
cColour = SetBkColor(hdcTemp, kTransparentColour);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
SetBkColor(hdcTemp, cColour);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
-
Re: MFC : Make a bitmap with a transparant color
I'm trying many things and I think I really near of the solution,
wrinting this code :
Code:
// Copy the destination to the screen.
BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);
//************************************************************
CBitmap Bitmap;
CDC MemDC;
CDC* pDC = CDC::FromHandle(hdc) ;
Bitmap.LoadBitmap(IDB_BITMAP1); // lecture bitmap dans les ressources
BITMAP InfosBmp; // structure d'informations.
Bitmap.GetBitmap(&InfosBmp);
MemDC.CreateCompatibleDC(pDC); // creation d'un DC en memoire
MemDC.SelectObject(&Bitmap); // selection du bitmap dans le DC en memoire
if (MemDC)
{
SelectObject(MemDC, &Bitmap); // selection du bitmap dans le DC en memoire
// transfert final du bitmap dans le dc de la view.
BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, MemDC, 0, 0, SRCCOPY);
DeleteDC(MemDC);
}
//************************************************************
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
I can see instead of my button the upper left corner of my backgroung,
how getting the position of the button to put it here :
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
to get the good background
-
Re: MFC : Make a bitmap with a transparant color
I got it !
Changing the background (in green) by the code in red, I got My background !
Code:
// Copy the background of the main DC to the destination.
//BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);
//************************************************************
CBitmap Bitmap;
CDC MemDC;
CDC* pDC = CDC::FromHandle(hdc) ;
Bitmap.LoadBitmap(IDB_BITMAP1); // lecture bitmap dans les ressources
MemDC.CreateCompatibleDC(pDC); // creation d'un DC en memoire
if (MemDC)
{
MemDC.SelectObject(&Bitmap); // selection du bitmap dans le DC en memoire
// transfert final du bitmap dans le dc de la view.
CRect rect ;
this->GetWindowRect(&rect) ;
this->GetParent()->ScreenToClient(&rect);
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, MemDC, rect.left, rect.top, SRCCOPY);
DeleteDC(MemDC);
}
//************************************************************
And now, I just have to past it properly
-
Re: MFC : Make a bitmap with a transparant color
Ok,
So my final code is :
Code:
//=====================================
// transparentbitmapbutton.h
//=====================================
#pragma once
#include "afxext.h"
class CTransparentBitmapButton :
public CBitmapButton
{
private:
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap);
// The colour inside this button's bitmap(s) that should be regarded as transparent
// is selected by the one of the pixel locate by X, Y
int m_iXPxlTranparent, m_iYPxlTranparent;
CBitmap m_BitmapBackground; // Background bitmap
BOOL m_BoolBackground; // Background exist ?
public:
CTransparentBitmapButton(int XPxlT, int YPxlT, UINT IDD_BITMAP = 0);
~CTransparentBitmapButton(void);
virtual void OnPaint();
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
//=====================================
// transparentbitmapbutton.cpp
//=====================================
#include "StdAfx.h"
#include ".\transparentbitmapbutton.h"
CTransparentBitmapButton::CTransparentBitmapButton(int XPxlT,int YPxlT, UINT IDD_BITMAP)
{
// Initialise the transparent pixel X,Y
m_iXPxlTranparent = XPxlT;
m_iYPxlTranparent = YPxlT;
m_BoolBackground = IDD_BITMAP != 0;
if (m_BoolBackground)
{
m_BitmapBackground.LoadBitmap(IDD_BITMAP); // lecture bitmap dans les ressources
}
}
CTransparentBitmapButton::~CTransparentBitmapButton(void)
{
}
// From 'OnPaint()
void CTransparentBitmapButton::OnPaint()
{
if ((GetParent()) && (GetParent()->IsIconic()))
{
CBitmapButton::OnPaint();
}
else
{
CPaintDC dc(this); // device context for painting
// At least onw bitmap must be loaded before calling 'Paint()'
ASSERT(m_bitmap.m_hObject != NULL);
// and we'll assume until we find otherwise, that
// the button is being drawn in its normal state.
CBitmap* pBitmap = &m_bitmap;
if ((!(IsWindowEnabled())) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(dc.m_hDC, *pBitmap);
}
}
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
// At least onw bitmap must be loaded before calling 'DrawItem()'
ASSERT(m_bitmap.m_hObject != NULL);
CBitmap* pBitmap = &m_bitmap;
UINT state = lpDrawItemStruct->itemState;
if ((state & ODS_SELECTED) && (NULL != m_bitmapSel.m_hObject))
pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && (NULL != m_bitmapFocus.m_hObject))
pBitmap = &m_bitmapFocus;
else if ((state & ODS_DISABLED) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(lpDrawItemStruct->hDC, *pBitmap);
}
void CTransparentBitmapButton::DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap)
{
BITMAP bm;
COLORREF cColour;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;
hdcTemp = CreateCompatibleDC(hdc);
if (HGDIOBJ hOldObj = SelectObject(hdcTemp, hBitmap)) // Select the bitmap
DeleteObject(hOldObj);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device to logical points
// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);
// Create a bitmap for each DC. DCs are required for a number of GDI functions.
// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));
// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
COLORREF transparentColour = GetPixel(hdcTemp, m_iXPxlTranparent, m_iYPxlTranparent);
if (transparentColour) cColour = SetBkColor(hdcTemp, transparentColour);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
SetBkColor(hdcTemp, cColour);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
// Copy the background of the main DC to the destination.
if (m_BoolBackground) // if bitmap background exist, use it
{
CDC MemDC;
CDC* pDC = CDC::FromHandle(hdc) ;
// Button location in the windows
CRect RectButton;
this->GetWindowRect(&RectButton) ;
this->GetParent()->ScreenToClient(&RectButton);
MemDC.CreateCompatibleDC(pDC); // creation of a DC in memory
MemDC.SelectObject(&m_BitmapBackground); // select bitmap in the DC in memory
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, MemDC, RectButton.left, RectButton.top, SRCCOPY);
DeleteDC(MemDC);
}
else
{
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);
}
// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
// Mask out the transparent coloured pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.
BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));
// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
Any comment ?
-
Re: MFC : Make a bitmap with a transparant color
Sorry for the delay - CodeGuru is very slow today, for some reason.
The code seems okay - but just bear in mind that it relies on the transparency colour being precisely right. If my experience is anything to go by - you can't rely on this with most 3rd party drawing packages. If you stipulate a particular colour, you may or may not get that colour in the final output. The final colour might be indistinguishable from the wanted colour - but "indistinguishable" isn't necessarily exact...! That's why I needed to put some code in to deal with "approximate" colours :)
-
Re: MFC : Make a bitmap with a transparant color
Ok, in fact, I put myself the transparancy colour on picture given by the graphical team, I fill all corner with only one colour, to get round rectangle button.
If necessary, I'll know where to find your code to get an approximative colour of transparancy :)
Thanks a lot for your help
-
Re: MFC : Make a bitmap with a transparant color
Last Update
I just modify the source code to get automatically it's parent window's image
Code:
#pragma once
#include "afxext.h"
class CTransparentBitmapButton :
public CBitmapButton
{
private:
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap);
// The colour inside this button's bitmap(s) that should be regarded as transparent
// is selected by the one of the pixel locate by X, Y
int m_iXPxlTranparent, m_iYPxlTranparent;
CBitmap m_BitmapBackground;
BOOL m_HasBackGround;
public:
CTransparentBitmapButton(int XPxlT, int YPxlT);
~CTransparentBitmapButton(void);
//virtual void OnPaint();
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
protected:
virtual void PreSubclassWindow();
};
#include "StdAfx.h"
#include ".\transparentbitmapbutton.h"
BEGIN_MESSAGE_MAP(CTransparentBitmapButton, CBitmapButton)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
CTransparentBitmapButton::CTransparentBitmapButton(int XPxlT,int YPxlT)
{
// Initialise the transparent pixel X,Y
m_iXPxlTranparent = XPxlT;
m_iYPxlTranparent = YPxlT;
m_HasBackGround = FALSE;
}
CTransparentBitmapButton::~CTransparentBitmapButton(void)
{
}
void CTransparentBitmapButton::PreSubclassWindow()
{
CBitmapButton::PreSubclassWindow();
CWnd *pParent = GetParent();
if (pParent)
{
CRect Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
pParent->ScreenToClient(&Rect);
CDC *pDC = pParent->GetDC();
m_BitmapBackground.CreateCompatibleBitmap(pDC,Rect.Width(),Rect.Height());
}
}
BOOL CTransparentBitmapButton::OnEraseBkgnd(CDC* pDC)
{
if (!m_HasBackGround)
{
CWnd *pParent = GetParent();
if (pParent)
{
CRect Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
pParent->ScreenToClient(&Rect);
CDC *pDC = pParent->GetDC();
CDC memdc;
memdc.CreateCompatibleDC(pDC);
CBitmap *oldbmp = memdc.SelectObject(&m_BitmapBackground);
memdc.BitBlt(0,0,Rect.Width(),Rect.Height(),pDC,Rect.left,Rect.top,SRCCOPY);
memdc.SelectObject(oldbmp);
m_HasBackGround = TRUE;
pParent->ReleaseDC(pDC);
}
}
return TRUE;
}
/*
// From 'OnPaint()
void CTransparentBitmapButton::OnPaint()
{
if ((GetParent()) && (GetParent()->IsIconic()))
{
CBitmapButton::OnPaint();
}
else
{
CPaintDC dc(this); // device context for painting
// At least onw bitmap must be loaded before calling 'Paint()'
ASSERT(m_bitmap.m_hObject != NULL);
// and we'll assume until we find otherwise, that
// the button is being drawn in its normal state.
CBitmap* pBitmap = &m_bitmap;
if ((!(IsWindowEnabled())) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(dc.m_hDC, *pBitmap);
}
}
*/
void CTransparentBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
// At least onw bitmap must be loaded before calling 'DrawItem()'
ASSERT(m_bitmap.m_hObject != NULL);
CBitmap* pBitmap = &m_bitmap;
UINT state = lpDrawItemStruct->itemState;
if ((state & ODS_SELECTED) && (NULL != m_bitmapSel.m_hObject))
pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && (NULL != m_bitmapFocus.m_hObject))
pBitmap = &m_bitmapFocus;
else if ((state & ODS_DISABLED) && (NULL != m_bitmapDisabled.m_hObject))
pBitmap = &m_bitmapDisabled;
DrawTransparentBitmap(lpDrawItemStruct->hDC, *pBitmap);
}
void CTransparentBitmapButton::DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap)
{
BITMAP bm;
COLORREF cColour;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;
hdcTemp = CreateCompatibleDC(hdc);
if (HGDIOBJ hOldObj = SelectObject(hdcTemp, hBitmap)) // Select the bitmap
DeleteObject(hOldObj);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device to logical points
// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);
// Create a bitmap for each DC. DCs are required for a number of GDI functions.
// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));
// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
COLORREF transparentColour = GetPixel(hdcTemp, m_iXPxlTranparent, m_iYPxlTranparent);
if (transparentColour) cColour = SetBkColor(hdcTemp, transparentColour);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
SetBkColor(hdcTemp, cColour);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
// Copy the background of the main DC to the destination.
if (m_HasBackGround)
{
CDC MemDC;
CDC* pDC = CDC::FromHandle(hdc) ;
BITMAP InfosBmp;
m_BitmapBackground.GetBitmap(&InfosBmp);
MemDC.CreateCompatibleDC(pDC);
MemDC.SelectObject(&m_BitmapBackground);
BitBlt(hdcMem, 0, 0, InfosBmp.bmWidth, InfosBmp.bmHeight, MemDC, 0, 0, SRCCOPY);
DeleteDC(MemDC);
}
else
{
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);
}
// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
// Mask out the transparent coloured pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.
BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));
// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
-
Re: MFC : Make a bitmap with a transparant color
Hi ,
I am facing a similar problem with MFC Dialog based application .I am supposed to load a image to a dilaog window..Till now i don't have any issues loading a rectangle shaped picture controls(in .bmp format) to the dialog.But now I got a requirement to load irregular picture control over the Dialog which gives me a white colored background and that is annoying.I could not find any solution after searching for long time.Please help me in.
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by
santoshg
I am facing a similar problem with MFC Dialog based application ....
I got a requirement to load irregular picture control over the Dialog which gives me a white colored background and that is annoying.
This thread is about how to "Make a bitmap with a transparant color".
What does your "annoying" problem have to do with this?
-
Re: MFC : Make a bitmap with a transparant color
Hi VictorN.
My Question is whether I can use the same bitmap by changing its background to a transparent color .so that my window's background will not be white.sorry if you think my question is improper because I am new to mfc.
-
Re: MFC : Make a bitmap with a transparant color
Quote:
sorry if you think my question is improper because I am new to mfc.
It's not that the question is improper - its that this thread is over 8 years old and it would have been more appropriate to start a new thread asking your specific question.
-
Re: MFC : Make a bitmap with a transparant color
Quote:
Originally Posted by
santoshg
My Question is whether I can use the same bitmap by changing its background to a transparent color .so that my window's background will not be white.sorry if you think my question is improper because I am new to mfc.
Your "Question" has nothing to do with MFC, as MFC provides nothing special in regard to bitmap drawing or transparency.
You need to explain your issue somewhat better. What do you think bitmap background is? What is your drawing procedure looks like? What is "rectangle shaped picture controls(in .bmp format)"? What is irregular picture control? What it has to do with the bitmap? With dialog?
The wording you use sounds kinda confusing, so how could we help you when we experience troubles with understanding?