Modify drawline method

martialarts

Well-known member
Joined
Jun 20, 2003
Messages
59
Location
Chicago Area
Hi. To make a long story shorter, I am creating a graph that resembles an ECG line (graphs heartbeat) but the line needs to change colors at certain dynamic intervals, often in the middle of a blood pulse. In other words, certain segments of the ECG line may have one or more color changes in the middle of them that currently I am trying to code by calling multiple instances of drawline but it is quite confusing and I think there should be a better way to do this.

Is it possible to overload the graphics class in order to overload the drawline method and have it check its position along the X axis before each pixel it draws? This would make the situation extremely easy to handle, more reliable, and would require less code.

Thanks in advance for any help or suggestions!
 
Are you trying to inherit the Graphics class? This wouldnt be possible since it is capped, i.e. noninheritable, which means that you can not extend its functionality in an object-oriented manner.

You could create your own static DrawLine method that could accept a Graphics object and parameters neccessary for a line, split the line into segments appropriately, and draw them with the appropriate colors using the Graphics object that was passed. (When it all gets compiled down to native code it would essentially be the same thing; it just wouldnt look as pretty in the code editor.)
 
Thats too bad. :( Basically all I need to do is have the pen used by drawline change throughout the line and if possible avoid manually separating it into individual lines by color. Is there any way to do this? Thanks.
 
Ah... I could have sworn there was a way to create a gradient pen, but no matter how hard I looked, I couldnt find a GradientPen or LinearGradientPen, so I concluded that I was wrong. I guess not; I was just looking for a different class when all I needed to do was look at the pens constructors.
 
The gradient pen might work but Im not exactly sure how it would work since I would need the gradient to change colors at specific points and those specific points would change dynamically from graph to graph. Also, it would be better if the color change was instant instead of blended. I am brute forcing my way through for the time being but if you guys have any more ideas, please let me know! Thanks.
 
Hmm, maybe a more detailed description of your requirements would help us help you. :)

The GDI+ Brush is very flexible. Perhaps PathGradientBrush or TextureBrush could be used.

Do you need the colors to change after the line is initially drawn? Sounds like a job for a DX Pixel Shader! :p
 
In the time that we were trying to find a more efficient way to do this I brute forced it. It was confusing and took 550 lines of code but it works. I will look into the other brushes that were mentioned for future use. Thanks a lot for the help.
 
Back
Top