65.9K
CodeProject is changing. Read more.
Home

CVisualEffect

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (17 votes)

May 17, 2004

1 min read

viewsIcon

64204

downloadIcon

1834

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.

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
{
// 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!