Graphics.SmoothingMode

image_pdfimage_print
   
 


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
   
class AntiAlias: Form
{
     public static void Main()
     {
          Application.Run(new AntiAlias());
     }
     public AntiAlias()
     {
          Text = "Anti-Alias Demo";
          BackColor = SystemColors.Window;
          ForeColor = SystemColors.WindowText;
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
          Pen      pen  = new Pen(ForeColor);
   
          grfx.SmoothingMode   = SmoothingMode.None;
   
          grfx.DrawLine(pen, 2, 2, 18, 10);
     }
}

    


DrawImage with size

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    Bitmap bmp = new Bitmap("rama.jpg");

    Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
    g.DrawImage(bmp, this.ClientRectangle);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


DrawImage with destination points

image_pdfimage_print
   
 


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    Bitmap bmp = new Bitmap("rama.jpg");
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    Point[] destinationPoints = {
      new Point(0, 0),    // destination for upper-left point of original
      new Point(100, 0),  // destination for upper-right point of original
      new Point(50, 100)};// destination for lower-left point of original
    g.DrawImage(bmp, destinationPoints);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


Fill the area 'bounded' by the path

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);
    GraphicsPath gp = new GraphicsPath();
    gp.AddLine(10, 10, 10, 50);
    gp.AddLine(10, 50, 50, 50);
    gp.AddLine(50, 50, 50, 10);
    gp.StartFigure();
    gp.AddLine(60, 10, 60, 50);
    gp.AddLine(60, 50, 100, 50);
    gp.AddLine(100, 50, 100, 10);
    gp.CloseFigure();

    Rectangle r = new Rectangle(110, 10, 40, 40);
    gp.AddEllipse(r);
    g.FillPath(Brushes.Orange, gp);
    g.DrawPath(Pens.Black, gp);
    gp.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


Rotate the text through 45 degrees

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);
    Font f = new Font("Times New Roman", 24);
    g.DrawString("Rotation", f, Brushes.Black, 0, 0);
    g.RotateTransform(45);
    g.DrawString("Rotation", f, Brushes.Black, 0, 0);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


Reset the transformation Translate by 30 pixels in vertical direction

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, ClientRectangle);

    g.DrawEllipse(Pens.Black, 20, 20, 30, 50);

    g.TranslateTransform(-15, 0);
    g.DrawEllipse(Pens.Black, 20, 20, 30, 50);

    g.ResetTransform();
    g.TranslateTransform(0, 30);
    g.DrawEllipse(Pens.Black, 20, 20, 30, 50);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


Apply the scaling transformation(scale subsequent operations by 2x horizontally and 3x vertically)

image_pdfimage_print
   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);
    g.DrawRectangle(Pens.Black, 10, 10, 50, 50);
    g.DrawEllipse(Pens.Black, 10, 10, 10, 10);

    g.ScaleTransform(2.0f, 3.0f);

    g.DrawRectangle(Pens.Black, 10, 10, 50, 50);
    g.DrawEllipse(Pens.Black, 10, 10, 10, 10);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}