How to draw pixel-level color gradients in CScrollView ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to draw pixel-level color gradients in CScrollView ?

Threaded View

  1. #1
    Join Date
    May 2002
    Posts
    1,717

    How to draw pixel-level color gradients in CScrollView ?

    I have a very general question. I wish to plot a mathematical function on a 2-dimensional grid. The function will be represented by 3 sets of floats, x-values, y-values, and z-values. Obviously, it is impossible to plot 3 such data sets on a 2D grid, so one approach is to use pixel coloration to represent the z-values.

    Those examples (and there are many to be found) show something like the function of the complex variable z, f(z) = exp(z). I have attached a exp(z).jpg example of the imaginary part of the plot exp(z).

    My question is: How to accomplish such a gradient colorization, assuming one already has the data?

    I have experimented with Gdiplus SetPixel, but I have not figured out how to produce a smooth gradient. Obviously, I'm in way over my head, but I had hoped someone might lead me in the right direction.

    Here's my attempt to create a simple gradient:
    Code:
    	CDC * pDC = GetDC();
    	Graphics graphics(pDC->m_hDC);
    
    	CRect r;
    	GetWindowRect(&r);
    	ScreenToClient(&r);
    
    	HWND hwnd = GetSafeHwnd();
    	CDC * pdc = GetDC();
    	HDC hdc = ::GetDC(hwnd);
    	COLORREF cr = RGB(192, 192, 192);
    	for(int x = 10; x <= 600; x++)
    	{
    		for(int y = 10; y <= 400; y++)
    		{
    			SetPixelV(hdc, x, y, cr); 
    			cr += 1;
    		}
    	}
    You can see my lame result also attached mygrad.jpg. Your thoughts greatly appreciated. How would you do this ?
    Attached Images Attached Images   
    mpliam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center