If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

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.

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

Originally Posted by Mike Pliam

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

You have to create a legend that associates certain values with certain colors and then interpolate intermediate values. Easiest way to interpolate colors is by just taking a linear combination of the red, green and blue values.

Originally Posted by Mike Pliam

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.

Besides the fact that you don't release the DCs, your use of SetPixelV seems ok, though that function can be slow. It's faster to assign to a bitmap of a memory DC and then bitblit to the window DC.
However, what is "cr += 1;" supposed to accomplish?

I'd suggest to forget about the graph and focus on the first problem first: how to assign a color to a value?

Last edited by D_Drmmr; October 7th, 2012 at 01:22 PM.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.