Search code examples
c#pointsystem.drawing

C# - Convert PointF to Point


I think it's a simple question but I cant figure it out.

//verifica qual o ponto mais proximo do centroide_circulo
PointF ponto_mais_proximo = pontos_medios.OrderBy(x => Math.Pow(x.X - centroide_circulo.X, 2) + Math.Pow(x.Y - centroide_circulo.Y, 2)).FirstOrDefault();

LineSegment2D linha_circulo_vertice = new LineSegment2D(centroide_circulo, ponto_mais_proximo);

cannot convert from 'System.Drawing.PointF' to 'System.Drawing.Point'

My question is how can i convert it? ponto_mais_proximo in the first line of code needs to be PointF.


Solution

  • The easiest way to do this is to use Point.Round():

    LineSegment2D linha_circulo_vertice = 
        new LineSegment2D(centroide_circulo, Point.Round(ponto_mais_proximo));
    

    Converts the specified PointF to a Point object by rounding the Point values to the nearest integer.