Groups | Blog | Home
all groups > dotnet drawing api > february 2006 >

dotnet drawing api : LinearGradientBrush - get color at point


Reda
2/28/2006 12:00:00 AM
Hi,
I used a LinearGradientBrush to fill a rectangle. This way I created
'legend' in my chart control.
Now I need to get color for specified point (value). I thought that I could
somehow get it using LinearGradientBrush, but it seems that I was wrong ;(

Alternatively I would have to create my own 'GradientBrush' with a method
like GetColorAtPoint(x,y). Am I right? Maybe there is another, easier
solution to do this?

Thanks in advance for any suggestions
Peter


Bob Powell [MVP]
2/28/2006 1:19:17 PM
If the linear gradient brush is truly linear you can calculate the colour
using a variant of the Bresingham line-drawing algorithm.

Unfortunately, Gradient brushes can be complex with additional features such
as curves or colour blends.

As a blatant cheat I would suggest creating a bitmap, drawing a gradient
onto it and then using GetPixel to retrieve the colour at the desired point.

--
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.



[quoted text, click to view]

Reda
3/1/2006 1:41:17 PM
Thanks a lot,
I think I will use your 'blatant cheat' suggestion ;)

Peter


U¿ytkownik "Bob Powell [MVP]" <bob@_spamkiller_.bobpowell.net> napisa³ w
wiadomo¶ci news:uCXIxEGPGHA.456@TK2MSFTNGP15.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button