将像素转换为点数

136

我需要将像素转换为C#中的点数。关于这个话题,我看到了一些复杂的解释,但似乎找不到简单的公式。假设标准的96dpi,我应该如何计算这个转换?

12个回答

0

在Mac上使用wxPython获取正确的DPI,如下所示:

    from wx import ScreenDC
    from wx import Size

    size: Size = ScreenDC().GetPPI()
    print(f'x-DPI: {size.GetWidth()} y-DPI: {size.GetHeight()}')

这将得到:
x-DPI: 72 y-DPI: 72
因此,公式为: points: int = (pixelNumber * 72) // 72

-2

将高度线转换为点和像素(使用自己的公式)。 以下是手动输入213.67点到行高字段的示例:

213.67  Manual Entry    
  0.45  Add 0.45    
214.12  Subtotal    
213.75  Round to a multiple of 0.75 
213.00  Subtract 0.75 provides manual entry converted by Excel  
284.00  Divide by 0.75 gives the number of pixels of height

这里手动输入213.67点得到284像素。
这里手动输入213.68点得到285像素。

(为什么是0.45?我不知道,但它有效。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接