【问题标题】:What is the best way to convert from a RectF to a Rect in Android?在 Android 中从 RectF 转换为 Rect 的最佳方法是什么?
【发布时间】:2013-05-08 19:57:00
【问题描述】:

我想在 Android 中从 RectF 转换为 Rect。目前我有:

RectF rectF = new RectF();
rectF.set( ... some values ... );

...

Rect rect = new Rect((int)rectF.left,
                     (int)rectF.top,
                     (int)rectF.right,
                     (int)rectF.bottom));

有没有更好的办法?

【问题讨论】:

  • 最好的方法是不需要在两者之间切换。如果必须这样做,那就是这样做的方法。如果您需要更高的准确性,您可以对值进行四舍五入,而不是通过强制转换截断它们,但在大多数情况下,这不是必需的。

标签: android graphics rectangles


【解决方案1】:

啊哈——找到答案了:

rectF.round(rect);

-- or --

rectF.roundOut(rect);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多