473,835 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

Many thanks in advance.

Brian
Nov 17 '05 #1
8 2420
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**********@p lease.com> wrote in message news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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**********@p lease.com> wrote in message news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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(PaintEv entArgs e)
{

e.Graphics.Smoo thingMode=Smoot hingMode.AntiAl ias;

GraphicsPath pth=new GraphicsPath();

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

Region rgn=new Region(pth);

rgn.Transform(n ew Matrix(1,0,0,1, 350,0));

e.Graphics.Fill Path(Brushes.Bl ack,pth);

e.Graphics.Fill Region(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**********@p lease.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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(PaintEv entArgs e)
{

e.Graphics.Smoo thingMode=Smoot hingMode.AntiAl ias;

GraphicsPath pth=new GraphicsPath();

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

Region rgn=new Region(pth);

rgn.Transform(n ew Matrix(1,0,0,1, 350,0));

e.Graphics.Fill Path(Brushes.Bl ack,pth);

e.Graphics.Fill Region(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**********@p lease.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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@_spamkille r_bobpowell.net > wrote in message news:eE******** ******@TK2MSFTN GP12.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(PaintEv entArgs e)
{

e.Graphics.Smoo thingMode=Smoot hingMode.AntiAl ias;

GraphicsPath pth=new GraphicsPath();

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

Region rgn=new Region(pth);

rgn.Transform(n ew Matrix(1,0,0,1, 350,0));

e.Graphics.Fill Path(Brushes.Bl ack,pth);

e.Graphics.Fill Region(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**********@p lease.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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@_spamkille r_bobpowell.net > wrote in message news:eE******** ******@TK2MSFTN GP12.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(PaintEv entArgs e)
{

e.Graphics.Smoo thingMode=Smoot hingMode.AntiAl ias;

GraphicsPath pth=new GraphicsPath();

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

Region rgn=new Region(pth);

rgn.Transform(n ew Matrix(1,0,0,1, 350,0));

e.Graphics.Fill Path(Brushes.Bl ack,pth);

e.Graphics.Fill Region(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**********@p lease.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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(Graphi cs g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.A ntiAlias;
g.PixelOffsetMo de = PixelOffsetMode .HighQuality;

CreatePaddle1Re gion();
CreatePaddle2Re gion();
CreatePuckPath( );

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

// paddle brushes
Brush paddleBr = new SolidBrush(Colo r.Black);
g.FillRegion(pa ddleBr, rgnPaddle1);
g.FillRegion(pa ddleBr, rgnPaddle2);
paddleBr.Dispos e();
}

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
2400
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 least scaled consistently. Charles
4
1328
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 informations. I used to do that using Tag property of an objects but ManuItem doesn't have anything like that. So how to add a Tag property to a MenuItem?
1
1215
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 control and keep the rest. pei
3
1199
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 the app: Exception Type: System.Resources.MissingManifestResourceException Message: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly.
1
1700
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 functions, like cute little rectangles or fancy text, it calls OnPaint and I'm fairly sure it's painting over what i just painted 3 nanoseconds ago, coz nothing is appearing. Good way around this prob? cheers
0
297
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 (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/~basquilletj/antialiasing.JPG
7
2947
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 2003. But since .NET also uses it, does that mean that it gets automatically installed when I install a .NET framework on a Windows 2000?
7
5979
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" Graphics object which is done as a side-effect to GetHDC() call - could you confirm? Another question that comes to my mind when planning mentioned operation is: if the control painted on uses double-buffering style, will GDI calls make use of "back...
1
2123
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 you run out. But consider the following code (in a timer elapsed event on a Windows Form): private void TimerFunc(object sender, System.Timers.ElapsedEventArgs e) { Graphics gdi = this.CreateGraphics();
0
9652
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10233
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3088
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.