对CImage进行动画处理以在创建时淡入 [英] Animating a CImage to fade in on creation

查看:133
本文介绍了对CImage进行动画处理以在创建时淡入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I currently have a CView which consists of a single centralized CImage which displays upon immediate loading of my application.

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

I want to prettify it a little by making the CImage fade in on startup instead of simply being displayed (I already have a splash-screen, so I'm not asking for how to animate a CWnd).

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

In order to display my image, I have overrided the CView::OnDraw method, as follows:

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值(我将作为成员保持该时间)多变的).

Now I'm not entirely sure how to go about fading it in on creation. My current plan of action is to create a timer based on std::chrono::steady_clock and change the alpha value of the CImage based on the difference between the current time point and the time at which the clock started (which I will keep as a member variable).

但是,我不确定如何整体更改图像的Alpha值吗?

However, I'm not sure how to change the alpha value of the image as a whole?

提前谢谢!

推荐答案

使用bySrcAlpha的值开始为255,并在计时器函数中将其递减适当的值.

Start the value of bySrcAlpha at 255 and decrement it by an appropriate value in your timer function.

这篇关于对CImage进行动画处理以在创建时淡入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆