Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Antialiasing / Smoothing

Learn how to apply antialiasing on shapes using GDI+. Uses SmoothingMode and PixelOffsetMode enumerations.

On Wednesday, May 26th 2004 at 11:11 AM
By Andrew Pociu (View Profile)
*****   (Rated 4.2 with 45 votes)
Contextual Ads
More C# Resources
Advertisement

Antialiasing = smoothing line edges in computer images: smoothing the jagged edges of diagonal lines in computer-generated images by varying the color or shades of gray at the edges
Microsoft® Encarta® Reference Library 2003. © 1993-2002 Microsoft Corporation. All rights reserved.


We all know what antialiasing is, probably most of us from games... when you try activating antialiasing in your favorite game the image is smoother but the graphics card lags so you go to the local store and $300 later you can play the game at a decent number of frames per second.

In some other tutorial at Geekpedia we used the OnPaint event to draw lines and other shapes on a form. As you probably saw, they weren't very smooth because they didn't had any antialiasing applied.
Using GDI+ it's a piece of cake to apply antialiasing effect on this shapes. Create a new 'Windows Application' project in Microsoft Visual C# .NET and give the new form a white background color (using the BackColor property).
Also in the multitude of 'using...' statements add the following:


using System.Drawing.Drawing2D;



We will use this namespace for using the SmoothingMode and PixelOffsetMode properties.

And here is the code:


protected override void OnPaint(PaintEventArgs paintEvnt)
{
    Graphics gfx = paintEvnt.Graphics;
    Pen myPen = new Pen(Color.Black);
    gfx.SmoothingMode = SmoothingMode.None;
    gfx.DrawEllipse(myPen, 20, 20, 100, 100);
    gfx.SmoothingMode = SmoothingMode.AntiAlias;
    gfx.DrawEllipse(myPen, 150, 20, 100, 100);
    gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gfx.DrawEllipse(myPen, 20, 150, 100, 100);
}


SmoothingMode


The SmoothingMode property creates the antialiasing that makes the graphic object render smoothly.

You can choose from the following enumerations:

Default: Specifies the default mode.
AntiAlias: Specifies antialiased rendering.
HighQuality: Specifies high quality, low speed rendering.
HighSpeed: Specifies high speed, low quality rendering.
Invalid: Specifies an invalid mode.
None: Specifies no antialiasing.

HighQuality is actually the same as AntiAlias and HighSpeed is the same as None.
In the example code we used SmoothingMode.None and SmoothingMode.AntiAlias to demonstrate.

PixelOffsetMode


PixelOffsetMode, also known as an antialiasing enhancement tries to make the shapes a bit more smooth.
As its name implies, PixelOffsetMode offsets pixels to improve the quality.
Perhaps the easiest way to understand what PixelOffsetMode does is to analyze the screenshot of the code we have created in this tutorial.
In the following screenshot, the first circle (top, left) is created without antialias (SmoothingMode.None), the second (top, right) is created using antialiasing (SmoothingMode.AntiAlias) and the third (lower, left) is created with PixelOffsetMode set to HighQuality (PixelOffsetMode.HighQuality).



You can easily see the difference between the circle created only with SmoothingMode.AntiAlias and the circle created with PixelOffsetMode.HighQuality. The coordinates are decreased by the size of half a pixel. Overall the image created with SmoothingMode.AntiAlias and PixelOffsetMode.HighQuality is a bit better than the one created only with SmoothingMode.AntiAlias, of course with the cost of performance.

PixelOffsetMode has the following possible enumerations:

Default: Specifies the default mode.
Half: Specifies that pixels are offset by -.5 units, both horizontally and vertically, for high speed antialiasing.
HighQuality: Specifies high quality, low speed rendering.
HighSpeed: Specifies high speed, low quality rendering.
Invalid: Specifies an invalid mode.
None: Specifies no pixel offset.
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by red on Friday, December 28th 2007 at 10:43 AM

first post!

by chris on Thursday, July 3rd 2008 at 12:08 AM

Thanks for the tips! I'm going to use it to make some antialiased graphs.
Cheers

by jeka911 on Saturday, January 31st 2009 at 08:58 AM

Thanks:)

by ChelOis on Saturday, March 14th 2009 at 10:10 AM

Excellent, much more better explanation than MSDN.
urgreat !!!

by ronak on Wednesday, April 1st 2009 at 01:04 AM

Excellent

by timo on Thursday, February 25th 2010 at 07:35 AM

Thank you!

by sda on Thursday, March 25th 2010 at 09:34 PM

asdasdasd

by mudassar on Thursday, March 25th 2010 at 09:35 PM

fucking information!!!! please improve your standard..

by tom on Wednesday, March 16th 2011 at 09:54 AM

Sooo, the information on MSDN is short and wrong. The information here is longer, but still complete balls. Did you actually think?

by bedroom design ideas on Saturday, August 13th 2011 at 06:17 AM

Communicate you for more integrated article. Where further could anyone get that empathic of assemblage in often a total way of utilise ? I talking a presentment tense point, and I am on the spotter for overmuch group.
<a href="http://homedecor7.com/category/bedroom/">bedroom design ideas</a>

by bedroom design ideas on Saturday, August 13th 2011 at 06:33 AM

Communicate you for more integrated article. Where further could anyone get that empathic of assemblage in often a total way of utilise ? I talking a presentment tense point, and I am on the spotter for overmuch group.

by sms on Tuesday, August 16th 2011 at 01:12 AM


ending in a necropolis add. I was allot dulled at cognition as no acquisition here at obligation. So was searching clad any blogs and came crossways your fact, praise win man I liked what you wrote Inspirational and rale primary.

by heartburn remedies on Friday, August 19th 2011 at 10:16 PM


The classification is depend on the realistic. There whatsoever capitalist that mix the determining with the worsened one. You moldiness trounce it understandably.

by be yourself quotes on Monday, November 7th 2011 at 07:32 PM

Before I read this article, I didn't understand ANYTHING on this subject but after a couple of hours analyzing this, I've come to master it!

by magazine subscriptions to Japan on Monday, December 12th 2011 at 04:54 AM

thank u for providing me information on List View.
I want to know how i can display data in datalist in Newsletter layout and Thank you so much, this is easy to understand and fun to continue along with. I am a migrating VB.NET/C# Developer looking for an insight into VC .NET. I've found the VC tutorials on many sites to be confusing, and the navigation around the sites to be near impossible to use! Thanks once again.

by Addison on Monday, January 9th 2012 at 05:03 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view

by gd poker on Sunday, January 22nd 2012 at 07:23 PM

Thank you for another informative blog. Where else could I get that kind of information written in such a perfect means? I have a challenge that I'm simply now working on, and I've been on the glance out for such information.

by Marco Island FL Real Estate on Sunday, February 5th 2012 at 10:27 PM

Communicate you for more integrated article. Where further could anyone get that empathic of assemblage in often a total way of utilise ? I talking a presentment tense point, and I am on the spotter for overmuch group.

by www.ForeclosureHelp.org on Friday, February 24th 2012 at 04:57 PM

Your blog is very informative. I really appreciate your hardwork. Thanks You for such good information. Keep up good work !!

by click here on Friday, March 2nd 2012 at 12:47 AM

When sampling is performed without removing this part of the signal, it causes undesirable artifacts such as the black-and-white noise

by AllAboutDivorce.com on Saturday, March 3rd 2012 at 10:28 AM

Anti-aliasing used to be a huge deal for Web designers. There were two sides to the issue - those who felt it was extremely important to do on all fonts and GIF images and those who felt that it caused more problems than it solved.

by AllAboutDivorce.com on Saturday, March 3rd 2012 at 10:28 AM

Anti-aliasing used to be a huge deal for Web designers. There were two sides to the issue - those who felt it was extremely important to do on all fonts and GIF images and those who felt that it caused more problems than it solved.

by AllAboutDivorce.com on Saturday, March 3rd 2012 at 10:29 AM

Anti-aliasing used to be a huge deal for Web designers. There were two sides to the issue - those who felt it was extremely important to do on all fonts and GIF images and those who felt that it caused more problems than it solved.
<a href="http://www.allaboutdivorce.net">AllAboutDivorce.com</a>

by ssara on Sunday, March 4th 2012 at 11:38 PM

Very interesting work. <a href="http://www.educationrequirements.net">EducationRequirements.net</a>

by EducationRequirements.net on Sunday, March 4th 2012 at 11:40 PM

Very interesting work.


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia
Other Resources
Bargain EZ Tech Coupons & Deals