Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC6 Pin
Jon Hulatt31-Jan-02 0:32
Jon Hulatt31-Jan-02 0:32 
GeneralModifyStyle() has no effect Pin
Rüpel30-Jan-02 2:51
Rüpel30-Jan-02 2:51 
GeneralRe: ModifyStyle() has no effect Pin
Joaquín M López Muñoz30-Jan-02 3:46
Joaquín M López Muñoz30-Jan-02 3:46 
GeneralRe: ModifyStyle() has no effect Pin
Rüpel30-Jan-02 3:56
Rüpel30-Jan-02 3:56 
GeneralRe: ModifyStyle() has no effect Pin
Joaquín M López Muñoz30-Jan-02 4:37
Joaquín M López Muñoz30-Jan-02 4:37 
GeneralColor of Cells Pin
Mazdak30-Jan-02 2:44
Mazdak30-Jan-02 2:44 
GeneralIAccessible->accLocation. Pin
Chagit30-Jan-02 2:20
Chagit30-Jan-02 2:20 
GeneralAlpha Blending Fade Effect Pin
Swinefeaster30-Jan-02 2:14
Swinefeaster30-Jan-02 2:14 
Hi all,

I'm trying to use the ::AlphaBlt function to perform a simple fade effect on the screen. Basically I need to create a transition between the current bitmap on a dc, and a new bitmap which is to "fade in".

I have hacked up the following code, and it works somewhat. The problem is that it is not smooth. Also, it takes way toooo much cpu to do, and this causes inconsistencies in timing. Usually in runs in about a few seconds at 1024x768, but on some machines at 1280x1024, it takes 10 seconds or worse! Frown | :(

Here's the code. Hopefully it won't be too hard to read through the irrelevant stuff...

void
cPkpPhotoImage::BlitStretchedFromProprietaryBlitEffectFade(CDC& DestDc,
const cRect& PassedSourceRect, const cRect& DestRect, uint32 rop,
const sEffectInfo& EffectInfo)const
{
LBitmap* Bitmap = GetBlitBitmap();

if(!Bitmap)
{
// Should not get here.
ASSERT(false);
}
else
{
cSize ThisSize = GetCurrentImageSize();
cRect SourceRect(ThisSize);

BLENDFUNCTION BlendInfo;
BlendInfo.BlendOp = AC_SRC_OVER;
BlendInfo.BlendFlags = 0;
BlendInfo.AlphaFormat = 0;
BlendInfo.SourceConstantAlpha = (BYTE)grain;

CDC ThisDc;
if(LockDcInternal(ThisDc, Bitmap))
{
cTimer Timer;
cTimeTag WhenCanProgress;

cBitmap NoFlickerBitmap(DestDc, DestRect.GetSize());
cDC NoFlickerBitmapDc(&NoFlickerBitmap, &DestDc);

// First copy what's in the dest dc onto our temporary bitmap so we
// can do the fade.
NoFlickerBitmapDc.BitBlt(0, 0, DestRect.GetWidth(),
DestRect.GetHeight(), &DestDc, DestRect.left, DestRect.top, rop);

int numIterations = ((256 / grain) * 2) + 1;
for(int i = 0; i < numIterations; i++)
{
// Do the alpha blend onto the temporary bitmap.
::AlphaBlend(NoFlickerBitmapDc.m_hDC, 0, 0,
DestRect.GetWidth(), DestRect.GetHeight(), ThisDc.m_hDC,
SourceRect.left, SourceRect.top, SourceRect.GetWidth(),
SourceRect.GetHeight(), BlendInfo);

// Now we wait a bit if we're too quick. Note that we do as much
// processing before waiting, to ensure delay accuracy.
for(;;)
{
if(Timer > WhenCanProgress)
{
// Can progress.
break;
}
else
{
int sleepTime = -(Timer - WhenCanProgress);

if(sleepTime > 0)
{
::Sleep(sleepTime - 2);
}
}
}

// Then blit that bitmap onto the dest dc.
DestDc.BitBlt(DestRect.left, DestRect.top, DestRect.GetWidth(),
DestRect.GetHeight(), &NoFlickerBitmapDc, 0, 0, rop);

WhenCanProgress = cTimeTag(Timer, delay);
}

// Now do the final, non-transparent blit.
{
DestDc.StretchBlt(0, 0, DestRect.GetWidth(), DestRect.GetHeight(),
&ThisDc, SourceRect.left, SourceRect.top, SourceRect.GetWidth(),
SourceRect.GetHeight(), rop);
}

UnlockDcInternal(ThisDc, Bitmap);
}
}
}

Note that I use NoFlickerBitmap (cBitmap is just an extended version of CBitmap), into which I create the composite semi faded image. This image I then opaquely blit onto the destination dc. I have to do this because ::AlphaBlend() doesn't do a nice clean blit; rather it does some kind of iterative scan, which can be seen and looks quite ugly.

One way I could do this is create a window over the region i was to fade, and just use the dialog fading code article. Unfortunately, this seems kind of like a hack, and I'm reluctant to do it. There must be a better way!
Confused | :confused:

Thanks!

swinefeaster

Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
GeneralRe: Alpha Blending Fade Effect Pin
Domenic Denicola30-Jan-02 3:18
Domenic Denicola30-Jan-02 3:18 
GeneralIE Settings Pin
Sonu Kapoor30-Jan-02 1:48
Sonu Kapoor30-Jan-02 1:48 
GeneralRe: IE Settings Pin
Joaquín M López Muñoz30-Jan-02 3:14
Joaquín M López Muñoz30-Jan-02 3:14 
GeneralRe: IE Settings Pin
.:: RockNix ::.30-Jan-02 3:53
.:: RockNix ::.30-Jan-02 3:53 
GeneralMouse Clicks in CListCtrl Pin
bishbosh0230-Jan-02 1:40
bishbosh0230-Jan-02 1:40 
GeneralRe: Mouse Clicks in CListCtrl Pin
Swinefeaster30-Jan-02 2:00
Swinefeaster30-Jan-02 2:00 
GeneralRe: Mouse Clicks in CListCtrl Pin
bishbosh0230-Jan-02 3:19
bishbosh0230-Jan-02 3:19 
GeneralRe: Mouse Clicks in CListCtrl Pin
Rüpel30-Jan-02 3:02
Rüpel30-Jan-02 3:02 
GeneralLink dependent libraries together withe the main EXE file Pin
EdgarBM30-Jan-02 1:08
EdgarBM30-Jan-02 1:08 
GeneralRe: Link dependent libraries together withe the main EXE file Pin
Joaquín M López Muñoz30-Jan-02 3:00
Joaquín M López Muñoz30-Jan-02 3:00 
GeneralRe: Link dependent libraries together withe the main EXE file Pin
EdgarBM30-Jan-02 21:43
EdgarBM30-Jan-02 21:43 
GeneralRe: Link dependent libraries together withe the main EXE file Pin
Joaquín M López Muñoz30-Jan-02 21:56
Joaquín M López Muñoz30-Jan-02 21:56 
GeneralRe: Link dependent libraries together withe the main EXE file Pin
EdgarBM31-Jan-02 1:17
EdgarBM31-Jan-02 1:17 
GeneralLoading a directory into a Combo Control Pin
athick30-Jan-02 0:32
athick30-Jan-02 0:32 
QuestionHow get a rotated standard region Pin
wangyiming30-Jan-02 0:04
wangyiming30-Jan-02 0:04 
AnswerRe: How get a rotated standard region Pin
Joaquín M López Muñoz30-Jan-02 0:53
Joaquín M López Muñoz30-Jan-02 0:53 
Generalhey all, i need help. in a real bind here Pin
Cnoob29-Jan-02 23:26
Cnoob29-Jan-02 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.