适配屏幕分辨率

适配屏幕分辨率

直接上代码:参考注释

public static Rect calRealSceenRect(Rect rectFace, int width, int height, int rotation ,Boolean isBackCamera) {
        int oriention;
        oriention = rotation / 90;
        Rect rect = new Rect(rectFace);
        for (int i = 0; i < oriention; i++) {
            for (int j = 0; j < 4; j++) {
                int tempt = rect.top;
                rect.top = rect.right;
                rect.right = rect.bottom;
                rect.bottom = rect.left;
                rect.left = tempt;
            }
        }


        //0 横屏 对应竖屏
        int tempt = rect.top;
        rect.top = rect.left;
        rect.left = rect.bottom;
        rect.bottom = rect.right;
        rect.right = tempt;

        //前置 需要镜像
        if (!isBackCamera){
            int tempMirror=rect.top;
            rect.top=rect.bottom;
            rect.bottom=tempMirror;
        }

        //计算实际宽高的高度差  就转化完成android的标准坐标系。
        rect.left = height - rect.left;
        rect.right = height - rect.right;

        if (!isBackCamera) {
            rect.top = width - rect.top;
            rect.bottom = width - rect.bottom;
        }
  
        return rect;
    }

最后,欢迎大家一起交流学习:微信:liaosy666 ; QQ:2209115372 。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值