Learn how to use Anti-aliasing with lines, curves, and text in C# : https://blog.aspose.com/drawing/antialiasing-in-csharp/
The following topics are covered in this article:
Learn how to use Anti-aliasing with lines, curves, and text in C# : https://blog.aspose.com/drawing/antialiasing-in-csharp/
The following topics are covered in this article:
// This code example demonstrates how to implement antialiasing with lines and curves. | |
// Create Bitmap | |
Bitmap bitmap = new Bitmap(500, 500, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
// Initialize the Graphics object | |
Graphics graphics = Graphics.FromImage(bitmap); | |
// Set the smoothin mode | |
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; | |
graphics.Clear(Color.White); | |
// Initialize a Pen | |
Pen pen = new Pen(Color.Black, 5); | |
// Draw an Ellipse | |
graphics.DrawEllipse(pen, 10, 10, 980, 780); | |
// Draw a Curve | |
graphics.DrawCurve(pen, new Point[] { new Point(10, 700), new Point(250, 500), new Point(500, 10), new Point(750, 500), new Point(990, 700) }); | |
// Draw a Line | |
graphics.DrawLine(pen, 20, 20, 980, 780); | |
// Save the image | |
bitmap.Save("C:\\Files\\Antialiasing.png"); |
// This code example demonstrates how to implement antialiasing with lines and curves. | |
// Create Bitmap | |
Bitmap bitmap = new Bitmap(500, 500, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
// Initialize the Graphics object | |
Graphics graphics = Graphics.FromImage(bitmap); | |
// Set the smoothin mode | |
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; | |
graphics.Clear(Color.White); | |
// Define Font family | |
FontFamily fontFamily = new FontFamily("Arial"); | |
// Define Font | |
Font font = new Font(fontFamily, 30, FontStyle.Regular, GraphicsUnit.Pixel); | |
// Initialize a solid brush | |
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); | |
// Draw a string with text rendering hint as SingleBitPerPixel | |
graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; | |
graphics.DrawString("This is Single Bit Per Pixel String!", font, solidBrush, new PointF(10, 10)); | |
// Draw a string with text rendering hint as AntiAlias | |
graphics.TextRenderingHint = TextRenderingHint.AntiAlias; | |
graphics.DrawString("This is Anti Alias String!", font, solidBrush, new PointF(10, 60)); | |
// Save the image | |
bitmap.Save("C:\\Files\\AntialiasingText.png"); |