473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

graphical color interpolation

Hi,

I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.

Thanks,
Victor.

Aug 28 '07 #1
6 2748

"Victor" <vl****@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi,

I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.
Does this graph have to update in realtime? If not, then it is very
straightforward to set each pixel individually. I suggest each pixel is a
weighted average of all the points, where the weight is proportional to
Math.Exp(r, -n) where r is the distance between the pixel and the point and
n is a constant somewhere around 1.5, chosen to make the graph look good.
Aug 28 '07 #2
On Aug 28, 4:51 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Victor" <vla...@gmail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.com...
Hi,
I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.

Does this graph have to update in realtime? If not, then it is very
straightforward to set each pixel individually. I suggest each pixel is a
weighted average of all the points, where the weight is proportional to
Math.Exp(r, -n) where r is the distance between the pixel and the point and
n is a constant somewhere around 1.5, chosen to make the graph look good.
Thanks Ben. One more question. How do you set one pixel at a time?
Just draw a line with the same start and end point?

Aug 29 '07 #3

"Victor" <vl****@gmail.comwrote in message
news:11**********************@50g2000hsm.googlegro ups.com...
On Aug 28, 4:51 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"Victor" <vla...@gmail.comwrote in message

news:11**********************@k79g2000hse.googleg roups.com...
Hi,
I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.

Does this graph have to update in realtime? If not, then it is very
straightforward to set each pixel individually. I suggest each pixel is
a
weighted average of all the points, where the weight is proportional to
Math.Exp(r, -n) where r is the distance between the pixel and the point
and
n is a constant somewhere around 1.5, chosen to make the graph look good.

Thanks Ben. One more question. How do you set one pixel at a time?
Just draw a line with the same start and end point?
The Bitmap class has a SetPixel method. You could also create a uint[,]
representing the color values (I'd suggest PixelFormat.Format32bppPArgb for
this task) and use the Bitmap constructor that accepts a pointer. Then use
DrawImage to paint the whole Bitmap to the screen at once.

Something like this should work:

uint[,] pixels = new uint[w,h];
// fill in values
pinned (uint* p = pixels) {
return new Bitmap(w, h, w * 4, new IntPtr(p));
}
Aug 29 '07 #4
On Aug 29, 6:40 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Victor" <vla...@gmail.comwrote in message

news:11**********************@50g2000hsm.googlegro ups.com...


On Aug 28, 4:51 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Victor" <vla...@gmail.comwrote in message
>news:11**********************@k79g2000hse.googleg roups.com...
Hi,
I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.
Does this graph have to update in realtime? If not, then it is very
straightforward to set each pixel individually. I suggest each pixel is
a
weighted average of all the points, where the weight is proportional to
Math.Exp(r, -n) where r is the distance between the pixel and the point
and
n is a constant somewhere around 1.5, chosen to make the graph look good.
Thanks Ben. One more question. How do you set one pixel at a time?
Just draw a line with the same start and end point?

The Bitmap class has a SetPixel method. You could also create a uint[,]
representing the color values (I'd suggest PixelFormat.Format32bppPArgb for
this task) and use the Bitmap constructor that accepts a pointer. Then use
DrawImage to paint the whole Bitmap to the screen at once.

Something like this should work:

uint[,] pixels = new uint[w,h];
// fill in values
pinned (uint* p = pixels) {
return new Bitmap(w, h, w * 4, new IntPtr(p));

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Thanks again Ben. One more question. In your first reply you said that
"the weight is proportional to
Math.Exp(r, -n) " but Math.Exp() only takes one parameter. Can you
please clarify what you meant? Other than that, creating the bitmap
the way you suggested works great.

Aug 30 '07 #5

"Victor" <vl****@gmail.comwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
On Aug 29, 6:40 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"Victor" <vla...@gmail.comwrote in message

news:11**********************@50g2000hsm.googlegr oups.com...


On Aug 28, 4:51 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Victor" <vla...@gmail.comwrote in message
>>news:11**********************@k79g2000hse.google groups.com...
Hi,
I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects
the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.
>Does this graph have to update in realtime? If not, then it is very
straightforward to set each pixel individually. I suggest each pixel
is
a
weighted average of all the points, where the weight is proportional
to
Math.Exp(r, -n) where r is the distance between the pixel and the
point
and
n is a constant somewhere around 1.5, chosen to make the graph look
good.
Thanks Ben. One more question. How do you set one pixel at a time?
Just draw a line with the same start and end point?

The Bitmap class has a SetPixel method. You could also create a uint[,]
representing the color values (I'd suggest PixelFormat.Format32bppPArgb
for
this task) and use the Bitmap constructor that accepts a pointer. Then
use
DrawImage to paint the whole Bitmap to the screen at once.

Something like this should work:

uint[,] pixels = new uint[w,h];
// fill in values
pinned (uint* p = pixels) {
return new Bitmap(w, h, w * 4, new IntPtr(p));

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Thanks again Ben. One more question. In your first reply you said that
"the weight is proportional to
Math.Exp(r, -n) " but Math.Exp() only takes one parameter. Can you
please clarify what you meant? Other than that, creating the bitmap
the way you suggested works great.
oops, meant Math.Pow, which computes an exponent.
Aug 30 '07 #6
You could potentially use the points that you have as factors in a
ColorBlend. You'd need to normalise them by ensuring that their values
were between 0 and 1. See the beginners guide to GDI+ for more in-depth
discussion of the ColorBlend object.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

Victor wrote:
Hi,

I am a newbie in the C# graphical arena and I have the following
problem. I have a 2D disk in which I have a few points, each point
having x, y coordinates and also a value associated with it which
represents profit (or loss). What I want to do is to create a
background with a gradient going from red to green which reflects the
values of the existing points. I need to mention that the points do
not follow a linear gradient or any type of pattern.

Thanks,
Victor.
Aug 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jonas Ernst | last post by:
Hi, Can somebody give me some hints how to do a line interpolation without using floating point arithemtics? The function shall do a linear interpolation between 2 points (line interp?) and...
10
by: William Gill | last post by:
Being somewhat new to Python, and having a tendency to over complicate things in my class design, I was wondering if anyone can suggest a simple graphical or flowcharting tool that they use to...
2
by: Kun | last post by:
I have an html form that takes dates and inserts them into a mysql file. Currently, users have to type in dates in the yyyy-mm-dd format. As of now, this process works with the sql. However, I...
5
by: xandra | last post by:
i understood the concept of interpolation search. but i couldn't understand what would be the steps for that search. for example, if i'm searching for J in this file A A B E F H J M N N N N O P P...
5
by: different | last post by:
Hi, I have a program which reads a file containing integers in . The program reads the value of a variable every 2 seconds, then maps it to another interval, say , obtaining a new value. I already...
0
by: MonkeeSage | last post by:
There are several string interpolation functions, as well as string.Template. But here's yet another. This one emulates ruby's inline interpolation syntax (using #{}), which interpolates strings as...
0
ncochran
by: ncochran | last post by:
I need to create a windows application that will allow me to enter values for a triple linear interpolation. The program should output the answer to the center label when the user presses the "Go"...
10
by: John Passaniti | last post by:
(Note: This is not the same message I posted a week or so ago. The problem that prevented my previous attempt to work was a silly error in the template system I was using. This is a problem...
5
by: August Karlstrom | last post by:
Hi, Does anyone know the correct syntax to interpolate a class variable, $x say, inside a string? I tried "{self::$x}" but it produces the string {self::x}
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.