What is the difference between System.Drawing.Point and System.Drawing.PointF

24,746

Solution 1

I think PointF exists partly because System.Drawing.Graphics class supports transformation and anti-aliasing. For example, you can draw a line between discrete pixelx in anti-aliasing mode.

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        Pen pen = Pens.Red;
        // draw two vertical line
        e.Graphics.DrawLine(pen, new Point(100, 100), new Point(100, 200));
        e.Graphics.DrawLine(pen, new Point(103, 100), new Point(103, 200));
        // draw a line exactly in the middle of those two lines
        e.Graphics.DrawLine(pen, new PointF(101.5f, 200.0f), new PointF(101.5f, 300.0f)); ;
    }

and it will look like

this

without PointF those functionalities will be limited.

Solution 2

Point uses integer coordinates (int for X and Y).

PointF uses floating points (float for X and Y).

Share:
24,746
Rye
Author by

Rye

StringBuilder sbldr = new StringBuilder(); sbldr.append("Just Your Ordinary Programmer"); NSLog(@"%@", sbldr.toString());

Updated on July 09, 2022

Comments

  • Rye
    Rye almost 2 years

    What is the difference between System.Drawing.Point and System.Drawing.PointF. Can you give an example between this two.

    Thanks in advance.