System.Drawing.Point和System.Drawing.PointF有什么区别

Rye*_*Rye 20 c# system.drawing winforms

System.Drawing.Point和之间有什么区别System.Drawing.PointF.你能举两个这样的例子吗?

提前致谢.

Jon*_*eet 29

Point使用整数坐标(intfor XY).

PointF使用浮点(floatfor XY).

  • @Rye:我相信大多数Windows窗体使用整数坐标系,而大多数WPF使用基于"双"的坐标系. (2认同)

tia*_*tia 22

我认为PointF存在的部分原因是System.Drawing.Graphics类支持转换和抗锯齿.例如,您可以在抗锯齿模式下在离散像素x之间绘制一条线.

    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)); ;
    }
Run Code Online (Sandbox Code Playgroud)

它看起来像

这个

没有PointF这些功能将是有限的.