C++ 设置CImage动画以在创建时淡入
我目前有一个C++ 设置CImage动画以在创建时淡入,c++,image,winapi,mfc,C++,Image,Winapi,Mfc,我目前有一个CView,它由一个集中的CImage组成,在立即加载我的应用程序时显示 我想通过使CImage在启动时淡入而不是简单地显示(我已经有了一个启动屏幕,所以我不想问如何设置CWnd)来美化它 为了显示我的图像,我覆盖了CView::OnDraw方法,如下所示: void CWelcomeView::OnDraw( _In_ CDC* pDC ) { CView::OnDraw( pDC ); static CImage backgroundImage; st
CView
,它由一个集中的CImage
组成,在立即加载我的应用程序时显示
我想通过使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::stable_clock
创建一个计时器,并根据当前时间点和时钟开始时间(我将保留为成员变量)之间的差异更改CImage
的alpha值
但是,我不知道如何更改整个图像的alpha值
提前谢谢 不要使用
backgroundImage.Draw()
,而是使用
将bySrcAlpha
的值从255开始,并在计时器函数中按适当的值递减
backgroundImage.AlphaBlend(pDC->GetSafeHdc(), destRect
, CRect(0, 0, backgroundImage.GetWidth(), backgroundImage.GetHeight())
, bySrcAlpha);