0

我的数学一定很生疏。我必须想出一个已知的算法:

  • X
  • 是的
  • 宽度
  • 高度

文档中的元素并将它们转换到不同硬件设备上的相同区域。例如,正在为打印创建文档(假设 8.5"x11" 字母大小),然后该文档中的元素将被传输到专有的电子阅读器。

此外,关于电子阅读器的已知事实,屏幕为 825x1200 像素纵向。每英寸有 150 个像素。

我以点为单位给出了打印文档中的源元素(每英寸 72 个 Postscript 点)。

到目前为止,我有一个接近的算法,但它需要准确,我觉得我需要将纵横比合并到图片中。我现在正在做的是:

x (in pixels) = ( x(in points)/width(of document in points) ) * width(of ereader in pixels)

等等

有什么线索吗?

谢谢!

4

2 回答 2

1

You may want to revert the order of your operations to reduce the effect of integer truncation, as follows:

x (in pixels) =  x(in points) * width(of ereader in pixels) / width(of document in points)

I don't think you have an aspect ratio problem, unless you forgot to mention that your e-reader device has non-square pixels. In that case you will have a different amount of pixels per inch horizontally and vertically on the device's screen, so you will use the horizontal ppi for x and the vertical ppi for y.

于 2012-05-10T15:33:38.847 回答
0

assuming your coordinates are integer numbers, the formula x/width is truncating (integer division). What you need is to perform the division/multiplication in floating point numbers, then truncate. Something like

(int)(((double)x)/width1*width2)

should do the trick (using C-like conversion to double and int)

于 2012-05-10T15:29:18.223 回答