Introduction
In this article, I want to show you a way for creating a simple visual effect. I use some image processing techniques and a very useful library called CImg written by David Tschumperlé to create this CStatic
derived funny control.
How to use
First of all, add the following files to your project: VisualEffect.h, VisualEffect.cpp, CImg.h and CImg.cpp. Most of the work for creating the images on the fly was done in CImg.h header file. In VisualEffect.h, two classes were defined: CVisualEffect
and CImgDisplayEx
(an extended version of CImgDisplay
for adapting it with our CStatic
derived class: CVisualEffect
).
In the dialog resource editor, add new static control and rename its ID from IDC_STATIC
to IDC_VISUAL_EFFECT
. See figure 2 for more information.
Run class wizard for assigning new member variable to your dialog as type of CVisualEffect
(Figure 3).
If class wizard couldn't recognize CVisualEffect
class, select CStatic
, then rename type of your variable from CStatic
to CVisualEffect
. Remember that you must add #include "VisualEffect.h"
at the top of your dialog header file.
CVisualEffect
class has two important member functions:
void SetImage(CString FileName);
Use this member function for setting an image to be loaded by the class. The class will show the effected image after calling DrawImage()
member function.
void DrawImage();
This member function must create visually effected images on the fly and show them with the help of a thread.
CVisualEffect class
The CVisualEffect
is a CStatic
derived class and has the following definition:
class CVisualEffect : public CStatic
{
public:
CVisualEffect();
void SetImage(CString FileName);
void DrawImage();
public:
CImg<float> m_Original;
CImgDisplayEx m_Display;
public:
static UINT DrawThread(LPVOID pParam);
virtual ~CVisualEffect();
protected:
DECLARE_MESSAGE_MAP()
};
m_Display
is a member variable of type CImgDisplayEx
. This class sets a target window for fast image manipulation.
Enjoy!
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from
Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acquisition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competition, my articles are:
You can see list of my articles, by clicking here