Click here to Skip to main content
15,879,239 members
Articles / Multimedia / GDI+

PngAnimation

Rate me:
Please Sign up or sign in to vote.
4.48/5 (9 votes)
1 Apr 2021Public Domain1 min read 5.6K   662   14   4
One of the easiest ways to animate images for your program
The article talks about a way to create an animated image to show that your program is currently doing some work.

Sample Image - maximum width is 600 pixels

Introduction

Often, the program needs to show that it is currently performing some action. For example, a project is being loaded, a device is being searched, data is being converted or new data is being generated. In such cases, animation is used. One of the easiest ways to do this is to draw a graphic file that looks like this:

Image 2

Frames are shown from left to right at regular intervals.

You can create such a file yourself or use one of the online services, for example loading.io. It is also possible to split some apng file into separate png files using the APNG Disassembler program. After that, using a graphical editor, they can be combined manually into one file.

Using the Code

To create the animation, do the following:

C++
#include "PngAnimation.h"

PngAnimation m_Anim;
   …
if( !m_Anim.Create(NULL,IDB_PNG1,31) )
    return -1;   // error.
m_Anim.Start(m_hWnd, 50,50, ::GetSysColor(COLOR_WINDOW), 40,true);

The PngAnimation object works with png files. It is created once, for example, when creating a window. Next, you only need to call the Start function. If you passed false as the last parameter of the Start, then after showing all parts of the png file, the animation will stop. To start it, you need to call the Start function again.

Also, a color is passed to the Start function, which is used to fill the area occupied by the PngAnimation before drawing it.

The PngAnimation object does not use MFC and can be used in a regular Win32 API application.

Good luck!

History

  • 31st March, 2021: Initial version

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer
Canada Canada

Comments and Discussions

 
QuestionInvoking this code through .NET Pin
Alex Lira8-Dec-21 9:25
Alex Lira8-Dec-21 9:25 
AnswerRe: Invoking this code through .NET Pin
Aleh Baradzenka8-Dec-21 9:35
Aleh Baradzenka8-Dec-21 9:35 
GeneralRe: Invoking this code through .NET Pin
Alex Lira8-Dec-21 9:53
Alex Lira8-Dec-21 9:53 
QuestionWhere is the article ? Pin
tbayart5-May-21 8:32
professionaltbayart5-May-21 8:32 

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.