Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Non-Linear gradient brushes?

Tags:

c#

gdi+

Is there a method I can use to generate non-linear Gradient brushes in c#?

To clarify: Im not looking for a gradient that can be applied to a non-linear path. Rather, I am looking for a gradient between 2 colours that fades between the two in a non-linear fashion i.e. the rate of changs is quicker at the start of the gradient and slows down as the brush nears the finishing point.

Is this even remotly possible in c# using gdi+?

like image 369
TK. Avatar asked Sep 16 '26 07:09

TK.


2 Answers

Yep, set the blend for the Brush.

LinearGradientBrush blendBrush = new LinearGradientBrush(Rectangle, Color.Red, Color.White, 360f);
Blend blend = new Blend();
blend .Factors = new float[] { 1.0f, 0.9f, 0.8f, 0.7f, 0.6f, 0.5f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f };
blend .Positions = new float[] { 0, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f };
blendBrush.Blend = blend ;

This example will start fading out, then go back to the previous colour. So a kinda fill from centre effect.

like image 58
Ian Avatar answered Sep 17 '26 20:09

Ian


Use the Blend property of LinearGradientBrush -

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.blend(VS.80).aspx

like image 22
Alex Avatar answered Sep 17 '26 21:09

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!