首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置CImage动画以在创建时淡入

设置CImage动画以在创建时淡入
EN

Stack Overflow用户
提问于 2013-06-13 03:46:53
回答 1查看 163关注 0票数 0

我目前有一个由单个集中式CImage组成的CView,它在我的应用程序立即加载时显示。

我想通过让CImage在启动时淡入而不是简单地显示(我已经有了一个闪屏,所以我不是在问如何为CWnd设置动画)来美化它。

为了显示我的图像,我重写了CView::OnDraw方法,如下所示:

代码语言:javascript
复制
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值?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-13 16:23:07

使用AlphaBlend而不是backgroundImage.Draw()

代码语言:javascript
复制
backgroundImage.AlphaBlend(pDC->GetSafeHdc(), destRect
    , CRect(0, 0, backgroundImage.GetWidth(), backgroundImage.GetHeight())
    , bySrcAlpha);

bySrcAlpha的值从255开始,并在您的计时器函数中将其递减适当的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17073998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档