- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我需要找到在屏幕上绘制的文本的宽度。 This thread建议 FontMetrics.stringWidth() 有时不如 FontMetrics.getStringBounds() 准确。
有谁知道这是否正确,如果正确,这种差异在什么情况下可见? FontMetrics.stringWidth() 似乎使用得更频繁,包括在 SwingUtilities.computeStringWidth() 中。此外,明显的优点是它不需要 Graphics 对象,但这本身与 Graphics 对象中定义的抗锯齿和类似设置的事实相结合可能解释了为什么 FontMetrics.getStringBounds() 可能更准确。
最佳答案
getStringBounds
有更多信息可以使用,因为它通过了 Graphics。它可以使用它来计算子像素字形放置并考虑抗锯齿对字形大小的影响。来自 FontRenderContext 的文档:
Anti-aliasing and Fractional-metrics specified by an application can also affect the size of a character because of rounding to pixel boundaries.
关于java - FontMetrics.stringWidth() 和 FontMetrics.getStringBounds() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7061060/
Java 中如何在没有 Graphics 实例的情况下获取文本前进(stringWidth)? 在doc examples ,stringWidth()取自FontMetrics,而FontMetri
这可能是一个非常简单的问题,但由于我真的不知道我在寻找什么,所以我无法成功找到解决方案...... 我正在使用 JLabel,在其中放置 html 字符串。我的字符串是通过 Jsoup 获取的然后,我
我需要找到在屏幕上绘制的文本的宽度。 This thread建议 FontMetrics.stringWidth() 有时不如 FontMetrics.getStringBounds() 准确。 有谁
我是一名优秀的程序员,十分优秀!