在每个方向上缩放RectF对象 [英] Scale RectF object in each direction

查看:357
本文介绍了在每个方向上缩放RectF对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在每个方向上按任意因子缩放RectF对象? 实际上,我会将RectF的大小调整为2倍(如果RectF为200X200,则我将其变为100x100)

It's possible to scale a RectF object of by an arbitrary factor in each direction? In practice i would resize of 2 factor a RectF (if RectF is 200X200 i would that he becomes 100x100)

推荐答案

尝试如下操作:

private void scale(RectF rect, float factor){
    float diffHorizontal = (rect.right-rect.left) * (factor-1f);
    float diffVertical = (rect.bottom-rect.top) * (factor-1f);

    rect.top -= diffVertical/2f;
    rect.bottom += diffVertical/2f;

    rect.left -= diffHorizontal/2f;
    rect.right += diffHorizontal/2f;
}

这是在没有测试的情况下完成的,但我认为它应该可以工作.这应将中心保持在同一位置并向外扩展.双方的面积都将增加一倍.

This is done without testing but I think it should work. This should keep the center in the same place and expand outward. All sides will be twice as big.

这篇关于在每个方向上缩放RectF对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆