How to draw a Gradient(as fog) background
-
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
-
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
How about the GDI+. check the Graphics classs and LinerGradientBrush in the GDI+.
nave [OpenedFileFinder]
-
How about the GDI+. check the Graphics classs and LinerGradientBrush in the GDI+.
nave [OpenedFileFinder]
-
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
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
-
-
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
-