Scale RectF object in each direction

放肆的年华 提交于 2019-12-12 18:03:41

问题


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)


回答1:


Try something like this:

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.



来源:https://stackoverflow.com/questions/21779482/scale-rectf-object-in-each-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!