SemiTransparent Bitmaps
Posted
by Anon E. Mous
on July 28th, 1999
Example and source code
void DrawSemiTransparentBitmap(CDC *pDstDC, int x, int y, int nWidth, int nHeight,
CDC* pSrcDC, int xSrc, int ySrc)
{
CDC dcCompatible;
CBitmap *pBitmapOld;
CBitmap bm;
dcCompatible.CreateCompatibleDC(pDstDC);
bm.CreateCompatibleBitmap(pDstDC, nWidth, nHeight);
pBitmapOld = dcCompatible.SelectObject(&bm);
dcCompatible.FillSolidRect(CRect(0, 0, nWidth, nHeight), RGB(0x7F, 0x7F, 0x7F));
pDstDC->BitBlt(x, y, nWidth, nHeight, &dcCompatible, 0, 0, SRCAND);
dcCompatible.SelectObject(pBitmapOld);
pDstDC->BitBlt(x, y, nWidth, nHeight, pSrcDC, 0, 0, SRCPAINT);
}
More information
To display a bitmap (Say A) over another (B) to produce a result where A and B is visible you must divide each pixel of A by a constant, divide each pixel of B by another constant and add the two results.Result = A*a + B*(1-a) where "a" is a weight factor
The first BitBlt remove the higher bit of each pixel in the destination context and the second add the source context over the destination context. This will result in some saturation of bright colors but is not a problem in most applications.
Result = (A and 0x7F) + B
Result = A + B


Comments
sample! sample! sample!!!
Posted by mero_max on 11/13/2006 11:39pmi wanna see sample too please attach sample please!
ReplyU should have given a sample project
Posted by jayender.vs on 06/29/2006 03:23amWell dude, Its really looks good to see the semi transparent project , but it would have be even better (great) if u provide a sample project here, so that we can see how it is really done instead of thinking were to place the code .., if possible please attach a sample here. Ciao, Jay
ReplyWrite your own damn sample program
Posted by Legacy on 11/07/2003 12:00amOriginally posted by: gatkinso
Isn;t it enought that the author wrote the routine for you? Must you be spoon fed like an infant?
-
-
ReplySucks
Posted by jayender.vs on 06/29/2006 03:27amHello dude, Its worse to read a comment .. this is somthing that really helps many people here ,and its not difficult for the author to provide the sample project instead of giving the code...hope u understand. nothing wrong in providing the sample, it actually helps the people here who wants it very urgently instead of spending time in it .
ReplySpoons
Posted by dogbear on 03/31/2006 05:40amWaaah!
Replysample program
Posted by Legacy on 10/08/2003 12:00amOriginally posted by: karim
Please is it possible to have this sample program
ReplyThanks a lot.
best regards
Great! I looked for that formula for quiet a long time.
Posted by Legacy on 11/29/2001 12:00amOriginally posted by: Amit Gefen
Thnx
ReplyI want a sample program, too
Posted by Legacy on 09/04/2001 12:00amOriginally posted by: choi chang-ho
please! send me a sample program...
ReplyNow in Win98 and Win2K .. AlphaBlend()
Posted by Legacy on 08/02/2001 12:00amOriginally posted by: DarkByte
Starting with Windows 98 .. there is a new Display Context function available called AlphaBlend() .. i haven't figured out how it works exactly but i'm working on it. Meanwhile, you guys can do your own research on it and probably come up with good examples.
Here is the Syntax as show in the MSDN Library.
BOOL AlphaBlend(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);
Have fun with this !
Replyplz send me a sample program!!!
Posted by Legacy on 07/16/2001 12:00amOriginally posted by: fepest
thank for you.
Replyi need sample program.
plz. give me.
please give me source code
Posted by Legacy on 09/04/2000 12:00amOriginally posted by: yusun
ReplySemitransparent Bitmap
Posted by Legacy on 05/07/2000 12:00amOriginally posted by: Rodney Herrmann
Has anyone ever done anything similar to this with a window or dialog? I am interested in creating a window that is semi-transparent.
ReplyLoading, Please Wait ...