我目前有一个由单个集中式CImage组成的CView,它在我的应用程序立即加载时显示。
我想通过让CImage在启动时淡入而不是简单地显示(我已经有了一个闪屏,所以我不是在问如何为CWnd设置动画)来美化它。
为了显示我的图像,我重写了CView::OnDraw方法,如下所示:
void CWelcomeView::OnDraw( _In_ CDC* pDC )
{
CView::OnDraw( pDC );
static CImage backgroundImage;
static bool bImageLoaded = false;
if( !bImageLoaded )
{
backgroundImage.LoadFromResource( AfxGetInstanceHandle(), IDB_WELCOMESCREEN );
bImageLoaded = true;
}
CRect clientRect;
GetClientRect( &clientRect );
// The detination rectangle should be the same size as the image:
POINT pointTopLeft = {(clientRect.Width()-backgroundImage.GetWidth())/2, (clientRect.Height()-backgroundImage.GetHeight())/2};
CRect destRect( pointTopLeft, CSize( backgroundImage.GetWidth(), backgroundImage.GetHeight() ) );
// Draw the image in the right space:
backgroundImage.Draw( pDC->GetSafeHdc(), destRect );
}现在我不完全确定如何在创作中淡出它。我当前的行动计划是创建一个基于std::chrono::steady_clock的计时器,并根据当前时间点和时钟开始时间(我将其作为成员变量)之间的差异来更改CImage的Alpha值。
但是,我不确定如何改变整个图像的alpha值?
提前感谢!
发布于 2013-06-13 16:23:07
使用AlphaBlend而不是backgroundImage.Draw()
backgroundImage.AlphaBlend(pDC->GetSafeHdc(), destRect
, CRect(0, 0, backgroundImage.GetWidth(), backgroundImage.GetHeight())
, bySrcAlpha);将bySrcAlpha的值从255开始,并在您的计时器函数中将其递减适当的值。
https://stackoverflow.com/questions/17073998
复制相似问题