android 4.4 Camera

本文介绍如何在MTK相机中动态添加预览尺寸选项,并解析了代码中实现这一功能的具体逻辑,包括如何获取设备屏幕宽高比,并据此筛选合适的预览比例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MTK camera,添加一个preview size 解释:

     刚接触android系统的开发时间不长,这些也是我在修改客户需求时所修改的问题,写的不够深入,只是简单的了解以下,高手请掠过,谢谢!

     camera菜单都是动态添加的,从camerasettings.java开始,这个文件有读取所有xml文件的空间,然后根据需要显示需要的菜单。

    if (pictureRatio != null) {
                List<String> supportedRatios = buildPreviewRatios(mContext, mParameters);
                filterUnsupportedOptions(group, pictureRatio, supportedRatios,
                        SettingChecker.ROW_SETTING_PICTURE_RATIO);
      }


     buildPreviewRatios(mContext, mParameters);代码如下:

        private static List<String> buildPreviewRatios(Context context, Parameters parameters) {
        List<String> supportedRatios = new ArrayList<String>();
        String findString = null;
        if (context != null && parameters != null) {
            double find = findFullscreenRatio(context, parameters);
            supportedRatios.add(SettingUtils.getRatioString(4d / 3)); //add standard ratio
            findString = SettingUtils.getRatioString(find);
            if (!supportedRatios.contains(findString)) { //add full screen ratio
                supportedRatios.add(findString);
            }
        }
        return supportedRatios;
    }

    public static double findFullscreenRatio(Context context, Parameters parameters) {
        double find = 16d / 9;
        if (context != null && parameters != null) {
            DisplayMetrics metrics = context.getResources().getDisplayMetrics();
            double fullscreen;
            if (metrics.widthPixels > metrics.heightPixels) {
                fullscreen = (double)metrics.widthPixels / metrics.heightPixels;
            } else {
                fullscreen = (double)metrics.heightPixels / metrics.widthPixels;
            }
            
            for (int i=0; i < RATIOS.length ;i++) {
                if (Math.abs(RATIOS[i] - fullscreen) < Math.abs(fullscreen - find)) {
                    find = RATIOS[i];
                }
         }
                    }
        List<Size> sizes = parameters.getSupportedPictureSizes();
        if (sizes != null) {
            for (Size size : sizes) {
                if (toleranceRatio(find, (double)size.width / size.height)) {
                    return find;
                } 
            }
            find = 16d / 9;
        }
        return find;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jack_ma1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值