当前位置:操作系统 > 安卓/Android >>

Android 技术总结(009)—— 设置相机拍照尺寸为最小支持尺寸

[java]
// 获取屏幕信息 
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()); 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,