在Graphics2D中进行双精度绘图的目的是什么?

时间:2022-05-16 12:08:52

Could anybody explain it to me?

有人可以向我解释一下吗?

You can't draw between pixels so why should I use float or double measuring when drawing? In Oracle's docs is written something about printer device, but it also can't paint between the smallest points. I don't understand it.

你不能在像素之间绘制,所以为什么我应该在绘图时使用浮点数或双重测量?在Oracle的文档中写了一些关于打印机设备的东西,但它也无法在最小的点之间绘制。我不明白。

Let's say a simple line. This line has set width 1.3f. What is going on with it when it's drawn on:

让我们说一个简单的路线。这条线的宽度设置为1.3f。当它被绘制时,它是怎么回事:

  1. display in windows (I believe it has 96 DPI)?
  2. 在windows中显示(我相信它有96 DPI)?

  3. printer with 300 DPI?
  4. 打印机有300 DPI?

AFAIK Java uses 72 DPI internally. So how is the math?

AFAIK Java在内部使用72 DPI。那数学怎么样?

1 个解决方案

#1


0  

Several use cases come to mind.

想到几个用例。

  • Your graphics device might be scaled. For example I know of several applications which draw a window-filling image of the unit circle, i.e. a circle of radius 1, using an appropiate scaling of the graphics context.
  • 您的图形设备可能会缩放。例如,我知道几种应用,其使用图形上下文的适当缩放来绘制单位圆的窗口填充图像,即半径为1的圆。

  • You might be producing output for a vector-oriented target, like a PDF file. In that case, users might zoom in arbitrarily, and might expect a fair amount or precision even at high resolutions.
  • 您可能正在为面向向量的目标生成输出,如PDF文件。在这种情况下,用户可以任意放大,即使在高分辨率下也可能期望相当大的数量或精度。

  • Printers, like you mention, might print at a resolution much higher than the screen, which is accomplished by a built-in zoom factor that maps default coordinate units to several times the device pixel size.
  • 像你提到的那样,打印机可能以比屏幕高得多的分辨率进行打印,这是通过将默认坐标单位映射到设备像素大小的几倍的内置缩放系数来实现的。

  • Anti-aliasing suggest sub-pixel resolution. The amount of color applied to a given pixel at the boundary of a geometric object will depend on the sub-pixel coordinates of said object.
  • 抗锯齿建议使用亚像素分辨率。在几何对象的边界处施加到给定像素的颜色量将取决于所述对象的子像素坐标。

None of the above would readily rule out using single precision floats, and in fact most G2D operations are available using floats as well. Using doubles is only important for really large zooms, really strong demands in terms of precision, and similar applications. But on the other hand, most computations are performed on doubles in any case, and the overhead of carrying these as far through the graphics pipeline as possible is often negligible. So when you ask me why to use double instead of float, I ask you “why not?”

以上都不会轻易排除使用单精度浮点数,事实上大多数G2D操作也可以使用浮点数。使用双精度对于真正大的变焦,对精度和类似应用的强烈要求非常重要。但另一方面,大多数计算在任何情况下都是在双精度计算上执行的,并且尽可能通过图形管道传输这些计算的开销通常可以忽略不计。所以当你问我为什么要使用double而不是float时,我问你“为什么不呢?”

#1


0  

Several use cases come to mind.

想到几个用例。

  • Your graphics device might be scaled. For example I know of several applications which draw a window-filling image of the unit circle, i.e. a circle of radius 1, using an appropiate scaling of the graphics context.
  • 您的图形设备可能会缩放。例如,我知道几种应用,其使用图形上下文的适当缩放来绘制单位圆的窗口填充图像,即半径为1的圆。

  • You might be producing output for a vector-oriented target, like a PDF file. In that case, users might zoom in arbitrarily, and might expect a fair amount or precision even at high resolutions.
  • 您可能正在为面向向量的目标生成输出,如PDF文件。在这种情况下,用户可以任意放大,即使在高分辨率下也可能期望相当大的数量或精度。

  • Printers, like you mention, might print at a resolution much higher than the screen, which is accomplished by a built-in zoom factor that maps default coordinate units to several times the device pixel size.
  • 像你提到的那样,打印机可能以比屏幕高得多的分辨率进行打印,这是通过将默认坐标单位映射到设备像素大小的几倍的内置缩放系数来实现的。

  • Anti-aliasing suggest sub-pixel resolution. The amount of color applied to a given pixel at the boundary of a geometric object will depend on the sub-pixel coordinates of said object.
  • 抗锯齿建议使用亚像素分辨率。在几何对象的边界处施加到给定像素的颜色量将取决于所述对象的子像素坐标。

None of the above would readily rule out using single precision floats, and in fact most G2D operations are available using floats as well. Using doubles is only important for really large zooms, really strong demands in terms of precision, and similar applications. But on the other hand, most computations are performed on doubles in any case, and the overhead of carrying these as far through the graphics pipeline as possible is often negligible. So when you ask me why to use double instead of float, I ask you “why not?”

以上都不会轻易排除使用单精度浮点数,事实上大多数G2D操作也可以使用浮点数。使用双精度对于真正大的变焦,对精度和类似应用的强烈要求非常重要。但另一方面,大多数计算在任何情况下都是在双精度计算上执行的,并且尽可能通过图形管道传输这些计算的开销通常可以忽略不计。所以当你问我为什么要使用double而不是float时,我问你“为什么不呢?”