Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to draw a Gradient(as fog) background

How to draw a Gradient(as fog) background

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++performancecode-review
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HOW WHAT
    wrote on last edited by
    #1

    Hi, i need draw a fog background, i search Internet find a source, but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example. Thanks. // GradientRender.h: interface for the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) #define AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CGradientRender { private: unsigned char* m_Data; void ApplyTransformation(int width, int height); public: void DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor); CGradientRender(); virtual ~CGradientRender(); }; #endif // !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) // GradientRender.cpp: implementation of the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GradientRender.h" #include "math.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CGradientRender::CGradientRender() { m_Data = NULL; } CGradientRender::~CGradientRender() { if ( m_Data != NULL ) delete m_Data; } void CGradientRender::DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor) { int i, j; double r; int X, Y; double fi; // Calculate image size int width = rect.right - rect.left; int height = rect.bottom - rect.top; int size = height*width*4; double radius = sqrt( pow(height/2,2) + pow(width/2,2) ); double R = sqrt( pow(width/4,2) + pow(height/4,2) ); // Create data buffer m_Data = new unsigned char[size]; // Create gradient for ( i=0; i

    N N 2 Replies Last reply
    0
    • H HOW WHAT

      Hi, i need draw a fog background, i search Internet find a source, but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example. Thanks. // GradientRender.h: interface for the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) #define AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CGradientRender { private: unsigned char* m_Data; void ApplyTransformation(int width, int height); public: void DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor); CGradientRender(); virtual ~CGradientRender(); }; #endif // !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) // GradientRender.cpp: implementation of the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GradientRender.h" #include "math.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CGradientRender::CGradientRender() { m_Data = NULL; } CGradientRender::~CGradientRender() { if ( m_Data != NULL ) delete m_Data; } void CGradientRender::DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor) { int i, j; double r; int X, Y; double fi; // Calculate image size int width = rect.right - rect.left; int height = rect.bottom - rect.top; int size = height*width*4; double radius = sqrt( pow(height/2,2) + pow(width/2,2) ); double R = sqrt( pow(width/4,2) + pow(height/4,2) ); // Create data buffer m_Data = new unsigned char[size]; // Create gradient for ( i=0; i

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      How about the GDI+. check the Graphics classs and LinerGradientBrush in the GDI+.

      nave [OpenedFileFinder]

      H 1 Reply Last reply
      0
      • N Naveen

        How about the GDI+. check the Graphics classs and LinerGradientBrush in the GDI+.

        nave [OpenedFileFinder]

        H Offline
        H Offline
        HOW WHAT
        wrote on last edited by
        #3

        Oh, thanks. But i don't want use GDI+.

        H 1 Reply Last reply
        0
        • H HOW WHAT

          Hi, i need draw a fog background, i search Internet find a source, but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example. Thanks. // GradientRender.h: interface for the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) #define AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CGradientRender { private: unsigned char* m_Data; void ApplyTransformation(int width, int height); public: void DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor); CGradientRender(); virtual ~CGradientRender(); }; #endif // !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_) // GradientRender.cpp: implementation of the CGradientRender class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GradientRender.h" #include "math.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CGradientRender::CGradientRender() { m_Data = NULL; } CGradientRender::~CGradientRender() { if ( m_Data != NULL ) delete m_Data; } void CGradientRender::DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor) { int i, j; double r; int X, Y; double fi; // Calculate image size int width = rect.right - rect.left; int height = rect.bottom - rect.top; int size = height*width*4; double radius = sqrt( pow(height/2,2) + pow(width/2,2) ); double R = sqrt( pow(width/4,2) + pow(height/4,2) ); // Create data buffer m_Data = new unsigned char[size]; // Create gradient for ( i=0; i

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          HOW WHAT wrote:

          but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example.

          Use GradientFill.


          Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

          H 1 Reply Last reply
          0
          • H HOW WHAT

            Oh, thanks. But i don't want use GDI+.

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            See http://www.codeproject.com/bitmap/CGradientRender.asp[^]


            WhiteSky


            H 1 Reply Last reply
            0
            • N Nibu babu thomas

              HOW WHAT wrote:

              but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example.

              Use GradientFill.


              Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

              H Offline
              H Offline
              HOW WHAT
              wrote on last edited by
              #6

              But how to use GradientFill draw fog background...

              1 Reply Last reply
              0
              • H Hamid Taebi

                See http://www.codeproject.com/bitmap/CGradientRender.asp[^]


                WhiteSky


                H Offline
                H Offline
                HOW WHAT
                wrote on last edited by
                #7

                Those Question source code, copy from CGradientRender.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups