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;
}