I'm having problems with my LinearGradientBrush. I don't know if it's the time (1:43am here) or if I'm being stupid for some other reason, but this is really bugging me.
I have the following code:
using (LinearGradientBrush lgb = new LinearGradientBrush(
this.brightnessRectangle,this.fullcolour,Color.Black,LinearGradientMode.Vertical))
{
gradientImage = new Bitmap(50, 200, PixelFormat.Format32bppArgb);
using (Graphics newGraphics = Graphics.FromImage(gradientImage))
{
newGraphics.FillRectangle(lgb, new Rectangle(0, 0, 50, 200));
}
gradientImage.Save("test.png", ImageFormat.Png);
}
And yet test.png
looks like this:
Which, as I'm sure you'll be able to tell, was not the desired effect. It sort of looks like it's started to far down and wrapped back around, but the top and bottom anomalies are different sizes.
Anyone seen this before? Is it an easy fix?
Some notes:
LinearGradientBrush
to the one I have. Mine doesn't have StartPoint
or EndPoint
properties.Try making sure that brightnessRectangle
is equal to (0, 0, 50, 200).
In other words, make sure your LinearGradientBrush rectangle and your FillRectangle
are the same thing:
Rectangle r = new Rectangle(0, 0, 50, 200);
using (LinearGradientBrush lgb = new LinearGradientBrush(
r ,this.fullcolour,Color.Black,LinearGradientMode.Vertical)) {
gradientImage = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
using (Graphics newGraphics = Graphics.FromImage(gradientImage)) {
newGraphics.FillRectangle(lgb, r);
}
gradientImage.Save("test.png", ImageFormat.Png);
}
And yes, get some sleep.