Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day!

How to make the gradient of the curve, such as an ellipse, the color changed depending point on the ellipse from a certain point.

I use to draw DrawingContext

Is it possible to write your brush inherited from Brush or Gradientbrush?
Posted
Updated 1-Aug-13 1:48am
v2
Comments
FaraonKture 1-Aug-13 4:40am    
It's funny, i need to change the color of curve, and you gave links to the standard tools of linear gradients - it does not fit!
Sushil Mate 1-Aug-13 4:44am    
Your question doesn't say like this?
FaraonKture 1-Aug-13 4:56am    
Suppose there is a curve to change its color moving along this curve
Sushil Mate 1-Aug-13 5:03am    
can you show us your code. its difficult to answer like this. you mean to say you want to change the color of the curve gradient?

1 solution

No, in general case, you won't be able to create such a brush, brush classes are just not as much flexible. You would need to calculate colors for each individual pixel. This is a pretty simple thing, but it will take both development time, and some processing time.

I would recommend to do it in low level pixel by pixel using the class System.Windows.Media.Imaging.WriteableBitmap:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[^].

It will allow you working directly with an array of pixels and commit it to the bitmap at once when the calculations are done. I'm afraid any other approach could be prohibitively slow.

Alternatively, you could research the possibility of creation of a custom brush derived from the abstract class System.Windows.Media.GradientBrush or just System.Windows.Media.Brush:
http://msdn.microsoft.com/en-us/library/system.windows.media.gradientbrush.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.brush.aspx[^].

I'm not sure that creation of a gradient brush in the case you described is a good idea, if it is even possible. I doubt it. First approach will certainly work and won't be too difficult.

—SA
 
Share this answer
 
Comments
Maciej Los 1-Aug-13 15:58pm    
As for me... well explained!
+5
Sergey Alexandrovich Kryukov 1-Aug-13 17:27pm    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900