Antialiasing in GDI+

Look at the difference between the following texts:

A careful observation will make us aware that the first string has a jagged effect and the second is smooth. (The effect will be more visible in the actual output). This is because we used antialiasing in the second one. The screen is divided into small pixels. When we try to draw curved objects on the screen they don�t perfectly map to a grid of pixels. This results in a jagged effect or �jaggies�. To remove this we use a technique called antialiasing Following is the code for this program:

protected void Form1_Paint ( object sender, System.WinForms.PaintEventArgs e )

Graphics g = e.Graphics ;
SolidBrush mybrush = new SolidBrush ( Color.Blue ) ;
Font myfont = new Font ( "Times new Roman", 25,
FontStyle.BoldItalic ) ;
Matrix mymat = new Matrix ( ) ;

mymat.Scale ( 5, 5 ) ;
g.Transform = mymat ;

g.DrawString ( "Cool", myfont, mybrush, 0, 0 ) ;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString ( "Cool", myfont, mybrush, 0, 30 ) ;


The TextRenderingHint is an enumeration which specifies the quality of text rendering. We equate the AntiAlias member of this enumeration to the TextRenderingHint property of the Graphics class.

Posted bySumedh at 9:32 PM  


Post a Comment