Android 技术总结(009)—— 设置相机拍照尺寸为最小支持尺寸
// 获取屏幕信息 WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); // 初始化相机 Camera camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(display.getWidth(), display.getHeight()); List<Camera.Size> pszize = parameters.getSupportedPictureSizes(); if (null != pszize && 0 < pszize.size()) { int height[] = new int[pszize.size()]; Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < pszize.size(); i++) { Camera.Size size = (Camera.Size) pszize.get(i); int sizeheight = size.height; int sizewidth = size.width; height[i] = sizeheight; map.put(sizeheight, sizewidth); } Arrays.sort(height); parameters.setPictureSize(map.get(height[0]), height[0]); } else { parameters.setPictureSize(display.getWidth(), display.getHeight()); }