473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Smoothing a linear gradient

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
4 5853
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

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Lindgren | last post by:
Hello! I am using Graphics.DrawString to draw some text on my usercontrols and I have discovered that when I turn on edge smoothing in Windows XP some of my drawn text appears as if it was bold....
5
by: Woody Splawn | last post by:
I have a webform where I would like to have the background color for the webform be a gradient in blue. How do I do this? What is the easiest way? What is the way most used by other developers? ...
13
by: Crirus | last post by:
The main ideea: I havea 513x513 array of values....I draw a sort of map using that values for colors... so I have a realistic lanscape (map). I want to zoom about 60 times that map...and the...
0
by: Don | last post by:
I'm making a custom control that has a multiline textbox on it. I want to make the textbox have a gradient background. On my custom control's Paint event I call a routine that draws a gradient on...
0
by: Patrick Dugan | last post by:
I am using Visual Studio 2005 with Visual Basic. I am trying to create a vertical color-gradient rectangle. I want the rectangle to go from red on top to blue on the bottom. This is the...
11
by: Maximus | last post by:
Hi all, Has anyone been able to reterive the gradient selection colors used in outlook 2003? Basically, I have a grid showing a list of records and my client wants the selected row to have the...
1
by: Robert W. | last post by:
In my WinForms app I've long been able to create a linear gradient effect by just intercepting the PaintEventHandler event. But I'd now like to create an inherited user control, specifically of a...
9
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer...
1
by: Bryon | last post by:
My current code paints a rectangular area at the top (under the menu and tool strip) and bottom (top of the status strip) of the main form with a linear gradient. The problem is that when the form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.