Click here to Skip to main content
15,888,113 members
Articles / Desktop Programming / MFC
Article

CVisualEffect

Rate me:
Please Sign up or sign in to vote.
3.00/5 (17 votes)
16 May 20041 min read 63.5K   1.8K   18   8
A CStatic derived class to show some visual effects on images.

Sample Image - VisualEffect1.jpg

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.

Image 2

Run class wizard for assigning new member variable to your dialog as type of CVisualEffect (Figure 3).

Image 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
{
// Construction
public:
    CVisualEffect();
    void SetImage(CString FileName);
    void DrawImage();

// Attributes
public:
    CImg<float>    m_Original;
    CImgDisplayEx    m_Display;


// Implementation
public:
    static UINT DrawThread(LPVOID pParam);
    virtual ~CVisualEffect();

    // Generated message map functions
protected:
    //{{AFX_MSG(CVisualEffect)
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()
};

m_Display is a member variable of type CImgDisplayEx. This class sets a target window for fast image manipulation.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Solaris Electronics LLC
United Arab Emirates United Arab Emirates
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


Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 19:49
professionalManoj Kumar Choubey26-Feb-12 19:49 
GeneralDeleting Image Pin
HeatherH21-Apr-07 7:38
HeatherH21-Apr-07 7:38 
Generalconvert Pin
denishernandez16-Feb-06 13:49
denishernandez16-Feb-06 13:49 
GeneralRe: convert Pin
Abbas_Riazi17-Feb-06 3:30
professionalAbbas_Riazi17-Feb-06 3:30 
GeneralCrashes in XP SP2 Pin
Balkrishna Talele1-Oct-04 20:07
Balkrishna Talele1-Oct-04 20:07 
GeneralAlmost worthless. Pin
WREY17-May-04 12:01
WREY17-May-04 12:01 
GeneralRe: Almost worthless. Pin
Abbas_Riazi17-May-04 18:34
professionalAbbas_Riazi17-May-04 18:34 
General100% CPU usage Pin
Anonymous17-May-04 11:12
Anonymous17-May-04 11:12 

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.