By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Smoothing a linear gradient

P: n/a
I'm drawing a linear gradient and its very "banded". The colors are far
enough part that it should be plenty smooth enough but I always get the same
number of bands regardless.

I've tried to set

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;

but doesn't help.

Any ideas?

Thanks,

Jon
Oct 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jon Slaughter wrote:
I'm drawing a linear gradient and its very "banded". The colors are far
enough part that it should be plenty smooth enough but I always get the same
number of bands regardless.

I've tried to set

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;
I placed the following code in my form's OnPaint method and the
gradient produced was smooth. I even switched my color depth on my
graphics adapter to medium quality and it was still smooth, so I'm not
sure what your problem may be. When creating the gradient brush, is
the width of the brush the same as the width of the area you are
painting? Can you post the code where you create the gradient brush?
Here is my sample code (in the OnPaint method):

LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new
Point(this.ClientRectangle.Width, 0), Color.Black, Color.White);

e.Graphics.FillRectangle(lgb, this.ClientRectangle);

Oct 26 '06 #2

P: n/a

"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Jon Slaughter wrote:
>I'm drawing a linear gradient and its very "banded". The colors are far
enough part that it should be plenty smooth enough but I always get the
same
number of bands regardless.

I've tried to set

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;

I placed the following code in my form's OnPaint method and the
gradient produced was smooth. I even switched my color depth on my
graphics adapter to medium quality and it was still smooth, so I'm not
sure what your problem may be. When creating the gradient brush, is
the width of the brush the same as the width of the area you are
painting? Can you post the code where you create the gradient brush?
Here is my sample code (in the OnPaint method):

LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new
Point(this.ClientRectangle.Width, 0), Color.Black, Color.White);

e.Graphics.FillRectangle(lgb, this.ClientRectangle);
This is my code. I believe it is essentially the same as yours.
Graphics g = e.Graphics;

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;

Brush B = new LinearGradientBrush(new Rectangle(Point.Empty, this.Size), c1,
c2, 45f);

g.FillRectangle(B, this.ClientRectangle);

B.Dispose();

The bands look like they are about 32 pixels wide.

Thanks,

Jon
Oct 26 '06 #3

P: n/a
Jon Slaughter wrote:
"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Jon Slaughter wrote:
I'm drawing a linear gradient and its very "banded". The colors are far
enough part that it should be plenty smooth enough but I always get the
same
number of bands regardless.

I've tried to set

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;
I placed the following code in my form's OnPaint method and the
gradient produced was smooth. I even switched my color depth on my
graphics adapter to medium quality and it was still smooth, so I'm not
sure what your problem may be. When creating the gradient brush, is
the width of the brush the same as the width of the area you are
painting? Can you post the code where you create the gradient brush?
Here is my sample code (in the OnPaint method):

LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new
Point(this.ClientRectangle.Width, 0), Color.Black, Color.White);

e.Graphics.FillRectangle(lgb, this.ClientRectangle);

This is my code. I believe it is essentially the same as yours.
Graphics g = e.Graphics;

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;

Brush B = new LinearGradientBrush(new Rectangle(Point.Empty, this.Size), c1,
c2, 45f);

g.FillRectangle(B, this.ClientRectangle);

B.Dispose();

The bands look like they are about 32 pixels wide.
Does each band go from the start color to the end color? Is this.Size
what you expect it to be?

When I first created my sample code above, my second Point made the
width of the gradient small so when I painted the entire form, I saw
the gradient repeat across the form. That's when I changed the second
Point to have an X coordinate that equalled the width of the client
area. Could that be what is happening?

Oct 26 '06 #4

P: n/a

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
Jon Slaughter wrote:
>"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegro ups.com...
Jon Slaughter wrote:
I'm drawing a linear gradient and its very "banded". The colors are
far
enough part that it should be plenty smooth enough but I always get
the
same
number of bands regardless.

I've tried to set

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;
I placed the following code in my form's OnPaint method and the
gradient produced was smooth. I even switched my color depth on my
graphics adapter to medium quality and it was still smooth, so I'm not
sure what your problem may be. When creating the gradient brush, is
the width of the brush the same as the width of the area you are
painting? Can you post the code where you create the gradient brush?
Here is my sample code (in the OnPaint method):

LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new
Point(this.ClientRectangle.Width, 0), Color.Black, Color.White);

e.Graphics.FillRectangle(lgb, this.ClientRectangle);

This is my code. I believe it is essentially the same as yours.
Graphics g = e.Graphics;

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.CompositingQuality = CompositingQuality.HighQuality;

g.SmoothingMode = SmoothingMode.HighQuality;

Brush B = new LinearGradientBrush(new Rectangle(Point.Empty, this.Size),
c1,
c2, 45f);

g.FillRectangle(B, this.ClientRectangle);

B.Dispose();

The bands look like they are about 32 pixels wide.

Does each band go from the start color to the end color? Is this.Size
what you expect it to be?

When I first created my sample code above, my second Point made the
width of the gradient small so when I painted the entire form, I saw
the gradient repeat across the form. That's when I changed the second
Point to have an X coordinate that equalled the width of the client
area. Could that be what is happening?
No, Becaues the top right corner is the proper color and the bottom right
ist he proper color and there is no repeat of those colors inbetween. It
looks like the title bar gradient in XP with no themes(I suppose it happens
in 2k too). But I cannot see any bands in the title bar(or barely) but its
obvious in my app.

this.Size returns the width and height of the form(Since I'm doing it in the
form) so its pretty large.

Thanks,
Jon
Oct 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.