android - 如何获取专为Android设备设计的前后摄像头的百万像素?

标签 android hardware

如何使用Android代码识别Android设备的前后摄像头的百万像素? 我尝试过 CameraInfo 但没有获得百万像素。例如,为了识别设备型号,我们使用这个 android.os.Build.MODEL 。同样,任何识别前置和后置摄像头百万像素的方法。预先感谢您的任何帮助。

如果设备是“Videocon A53”,则功能为(540x960 像素)显示屏并运行 Android 4.1 Jelly Bean、8 兆像素后置摄像头2-百万像素前置摄像头。现在我想通过android代码获得8兆像素和2兆像素

最佳答案

我通过结合堆栈溢出 friend 的三个不同答案得到了百万像素。

                Camera camera=Camera.open(0);    // For Back Camera
            android.hardware.Camera.Parameters params = camera.getParameters();
            List sizes = params.getSupportedPictureSizes();
            Camera.Size  result = null;

            ArrayList<Integer> arrayListForWidth = new ArrayList<Integer>();
            ArrayList<Integer> arrayListForHeight = new ArrayList<Integer>();

            for (int i=0;i<sizes.size();i++){
                result = (Size) sizes.get(i);
                arrayListForWidth.add(result.width);
                arrayListForHeight.add(result.height);
                Log.debug("PictureSize", "Supported Size: " + result.width + "height : " + result.height);  
                System.out.println("BACK PictureSize Supported Size: " + result.width + "height : " + result.height);  
            } 
            if(arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0){
                System.out.println("Back max W :"+Collections.max(arrayListForWidth));              // Gives Maximum Width
                System.out.println("Back max H :"+Collections.max(arrayListForHeight));                 // Gives Maximum Height
                            System.out.println("Back Megapixel :"+( ((Collections.max(arrayListForWidth)) * (Collections.max(arrayListForHeight))) / 1024000 ) );
            }
            camera.release();

            arrayListForWidth.clear();
            arrayListForHeight.clear();

            camera=Camera.open(1);        //  For Front Camera
            android.hardware.Camera.Parameters params1 = camera.getParameters();
            List sizes1 = params1.getSupportedPictureSizes();
            Camera.Size  result1 = null;
            for (int i=0;i<sizes1.size();i++){
                result1 = (Size) sizes1.get(i);
                arrayListForWidth.add(result1.width);
                arrayListForHeight.add(result1.height);
                Log.debug("PictureSize", "Supported Size: " + result1.width + "height : " + result1.height);  
                System.out.println("FRONT PictureSize Supported Size: " + result1.width + "height : " + result1.height);  
            } 
            if(arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0){
                System.out.println("FRONT max W :"+Collections.max(arrayListForWidth));
                System.out.println("FRONT max H :"+Collections.max(arrayListForHeight));
                            System.out.println("FRONT Megapixel :"+( ((Collections.max(arrayListForWidth)) * (Collections.max(arrayListForHeight))) / 1024000 ) );
            }

            camera.release();

要获得百万像素,(最大宽度 x 高)/1024000 = 百万像素

关于android - 如何获取专为Android设备设计的前后摄像头的百万像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19463858/

相关文章:

java - 如何在 Android 中使用 WebView 获取身份验证 token ?

c - 树莓派RS232问题

java - 扩展谷歌地图标记类

android - 如何防止 onItemSelected 在新实例化的 Spinner 上触发?

sockets - Easy Button to UDP 数据包 - 控制板术语

compiler-construction - 从硬件编写低级语言

hardware - 完美的*可编程*圣诞礼物!

linux - 从计算机体系结构的角度来看,应用程序是如何执行的

android - 如何在模拟器中启用即时应用程序选项

java - AdMob 显示状态为无效