473,394 Members | 1,679 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,394 software developers and data experts.

Quick GDI+ question..

Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian
Nov 17 '05 #1
8 2376
First off a jpg is not really a good format to display a sample of anti-aliasing in as it is a lossy format. BMP would
be better as it is lossless. jpg will naturally introduce it's own distortions depending on the amount of compression
used.

Second if you are working with anti-aliasing make sure you turn off anti-aliasing and anisotropic filtering in your
video driver.
Remember it's the video driver that ultimately paints what you see on your screen. In this case you want to see exactly
what your application is doing, not what the video driver is doing for you. And I can't imagine any two users in the
universe having the same exact same video configuration. Unless that configuration of setting are likely to make your
application crash that is:) Then it seems as if the whole known universe stumbles upon them.

Once you get to a known base state come back and let us know what is happening. I will probably tinker around with this
some more tonight and I will let you know if I discover anything unusual.
--
....Carl Frisk
Anger is a brief madness.
- Horace, 20 B.C.
http://www.carlfrisk.com
"Brian Basquille" <re**********@please.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the
edges of them out using anti-aliasing. Why is it that my puck (and neither of the paddles) is only looking like it's
been affected by this anti-aliasing, even though i apply the SmoothingMode property before drawing anything?

See what i mean here: http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian


Nov 17 '05 #2
First off a jpg is not really a good format to display a sample of anti-aliasing in as it is a lossy format. BMP would
be better as it is lossless. jpg will naturally introduce it's own distortions depending on the amount of compression
used.

Second if you are working with anti-aliasing make sure you turn off anti-aliasing and anisotropic filtering in your
video driver.
Remember it's the video driver that ultimately paints what you see on your screen. In this case you want to see exactly
what your application is doing, not what the video driver is doing for you. And I can't imagine any two users in the
universe having the same exact same video configuration. Unless that configuration of setting are likely to make your
application crash that is:) Then it seems as if the whole known universe stumbles upon them.

Once you get to a known base state come back and let us know what is happening. I will probably tinker around with this
some more tonight and I will let you know if I discover anything unusual.
--
....Carl Frisk
Anger is a brief madness.
- Horace, 20 B.C.
http://www.carlfrisk.com
"Brian Basquille" <re**********@please.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the
edges of them out using anti-aliasing. Why is it that my puck (and neither of the paddles) is only looking like it's
been affected by this anti-aliasing, even though i apply the SmoothingMode property before drawing anything?

See what i mean here: http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian


Nov 17 '05 #3
Hello Brian.
The problem lies in the fact that you're filling a path in one instance and
a region in another. The path is a record of graphical elements designed to
enable you to store lines and shapes. The region is a collection of
rectangles that are primarily concerned with restricting pixel output to a
specific area of the drawing surface.

When paths are stroked or filled the objects used such as bushes or pens are
subject to the settings of the GDI surface. When a region is filled then the
system simply restricts output on a pixel by pixel basis according the othe
content of the region.

This effect is demonstrated in the following code.

protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;

GraphicsPath pth=new GraphicsPath();

pth.AddEllipse(10,10,300,200);

Region rgn=new Region(pth);

rgn.Transform(new Matrix(1,0,0,1,350,0));

e.Graphics.FillPath(Brushes.Black,pth);

e.Graphics.FillRegion(Brushes.Black,rgn);

rgn.Dispose();

pth.Dispose();

base.OnPaint (e);

}

If you want smoothing you will need to draw the paddles with a graphicspath
as opposed to a region.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian

Nov 17 '05 #4
Hello Brian.
The problem lies in the fact that you're filling a path in one instance and
a region in another. The path is a record of graphical elements designed to
enable you to store lines and shapes. The region is a collection of
rectangles that are primarily concerned with restricting pixel output to a
specific area of the drawing surface.

When paths are stroked or filled the objects used such as bushes or pens are
subject to the settings of the GDI surface. When a region is filled then the
system simply restricts output on a pixel by pixel basis according the othe
content of the region.

This effect is demonstrated in the following code.

protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;

GraphicsPath pth=new GraphicsPath();

pth.AddEllipse(10,10,300,200);

Region rgn=new Region(pth);

rgn.Transform(new Matrix(1,0,0,1,350,0));

e.Graphics.FillPath(Brushes.Black,pth);

e.Graphics.FillRegion(Brushes.Black,rgn);

rgn.Dispose();

pth.Dispose();

base.OnPaint (e);

}

If you want smoothing you will need to draw the paddles with a graphicspath
as opposed to a region.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian

Nov 17 '05 #5
Same thing I just discovered. Makes sense when you look at it close enough.
Doesn't anyone sleep around here?

--
....Carl Frisk
Anger is a brief madness.
- Horace, 20 B.C.
http://www.carlfrisk.com
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:eE**************@TK2MSFTNGP12.phx.gbl...
Hello Brian.
The problem lies in the fact that you're filling a path in one instance and
a region in another. The path is a record of graphical elements designed to
enable you to store lines and shapes. The region is a collection of
rectangles that are primarily concerned with restricting pixel output to a
specific area of the drawing surface.

When paths are stroked or filled the objects used such as bushes or pens are
subject to the settings of the GDI surface. When a region is filled then the
system simply restricts output on a pixel by pixel basis according the othe
content of the region.

This effect is demonstrated in the following code.

protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;

GraphicsPath pth=new GraphicsPath();

pth.AddEllipse(10,10,300,200);

Region rgn=new Region(pth);

rgn.Transform(new Matrix(1,0,0,1,350,0));

e.Graphics.FillPath(Brushes.Black,pth);

e.Graphics.FillRegion(Brushes.Black,rgn);

rgn.Dispose();

pth.Dispose();

base.OnPaint (e);

}

If you want smoothing you will need to draw the paddles with a graphicspath
as opposed to a region.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian


Nov 17 '05 #6
Same thing I just discovered. Makes sense when you look at it close enough.
Doesn't anyone sleep around here?

--
....Carl Frisk
Anger is a brief madness.
- Horace, 20 B.C.
http://www.carlfrisk.com
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:eE**************@TK2MSFTNGP12.phx.gbl...
Hello Brian.
The problem lies in the fact that you're filling a path in one instance and
a region in another. The path is a record of graphical elements designed to
enable you to store lines and shapes. The region is a collection of
rectangles that are primarily concerned with restricting pixel output to a
specific area of the drawing surface.

When paths are stroked or filled the objects used such as bushes or pens are
subject to the settings of the GDI surface. When a region is filled then the
system simply restricts output on a pixel by pixel basis according the othe
content of the region.

This effect is demonstrated in the following code.

protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;

GraphicsPath pth=new GraphicsPath();

pth.AddEllipse(10,10,300,200);

Region rgn=new Region(pth);

rgn.Transform(new Matrix(1,0,0,1,350,0));

e.Graphics.FillPath(Brushes.Black,pth);

e.Graphics.FillRegion(Brushes.Black,rgn);

rgn.Dispose();

pth.Dispose();

base.OnPaint (e);

}

If you want smoothing you will need to draw the paddles with a graphicspath
as opposed to a region.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquill...tialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian


Nov 17 '05 #7
Cheers for that fellas!

Never even realised it after staring at that block of code for an half an
hour!!

Thanks again!

Brian
Nov 17 '05 #8
Cheers for that fellas!

Never even realised it after staring at that block of code for an half an
hour!!

Thanks again!

Brian
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Charles Law | last post by:
If I draw a rectangle, 6 inches by 2 inches, on a user control with a PageUnit of Inches, I get a rectangle of 7 by 2.2 inches. Is this what people would expect? I would have hoped that it was at...
4
by: Jacek Jurkowski | last post by:
I have to add a property to an object that is already allive. The problem is that I'm creating MainMenu from a definition file ... enyway , there is a need to add each menu item some extra...
1
by: pei_world | last post by:
Hi there, I have a problem about how to keep my draw graphics stay on my control unless I delete them. that means how to resist my graphics. also how to partially remove some graphics from my...
3
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my forms to a PNG graphic file on my hard drive, I get the following runtime error when I try to run...
1
by: David Sobey | last post by:
Hi I'm making a custom component using GDI+, a calendar grid thingy. I paint the grid and numbers in my overrided OnPaint. However, when i go to paint other things at other times in other...
0
by: Brian Basquille | last post by:
Hello all, Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the edges of them out using anti-aliasing. Why is it that my puck...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
1
by: Chris Dunaway | last post by:
When working with GDI+, calling the CreateGraphics method to draw on a control has normally been frowned upon and it is always emphasized to dispose of pens and brushes and other GDI objects lest...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.