2

How to identify front and back camera's Megapixel of an android device by using Android code? I had tried CameraInfo but am not getting megapixel. For example, To identify Model of device we are using this android.os.Build.MODEL . Likewise any method to identify Megapixel of front and back camera. Advance thanks for any help.

If the device is "Videocon A53" features are (540x960 pixel) display and runs Android 4.1 Jelly Bean, 8-megapixel rear camera, 2-megapixel front-facing camera. Now i want to get that 8 megapixel and 2 megapixel by android code

Sakthimuthiah
  • 2,606
  • 6
  • 26
  • 41

1 Answers1

4

I got megapixel by combining three different answers of stack overflow friends.

                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();

For obtaining megapixel, (Biggest Width x Height) / 1024000 = Megapixel

Sakthimuthiah
  • 2,606
  • 6
  • 26
  • 41
  • Hi @Sakthimuthiah, My Mobile Phone model is Samsung galaxy star pro GT-S7262. and this mobile specification details shows Samsung [website](http://www.samsung.com/in/consumer/mobile-phone/mobile-phone/smartphone/GT-S7262MKAINU-spec?subsubtype=android-mobiles)/user manual/purchased box having printed only 2MP, but when i am getting max resolution of this mobile is 2048x1536. so it gives approximately 3.072MP by following the above link/above code. so finally i said that above procedure is Not always gives correct result. please help me to find out correct megapixes in android mobile. – challa sathish kumar Feb 26 '14 at 11:00
  • Micromax Bolt A35 device specification shows 2MP(Mega Pixel) but it gives 2592 x 1936 resolution picture. by using above procedure ((2592x1936)/102400)= approximate 5MP it wrong result. So please help me to find out exact megapixels of given android mobile device. please refer my detailed question.[How to find exact camera megapixels in android mobile](http://stackoverflow.com/questions/22032036/how-to-find-exact-camera-megapixels-in-android-mobile). – challa sathish kumar Feb 26 '14 at 11:04
  • @Sakthimuthiah (Biggest Width x Height) / 1024000 = Megapixel. Replace 1024000 with 1000000 will give better results – Riskhan Mar 19 '14 at 06:59
  • I will try. Thanks. May i know the reason for replacement of 1000000 – Sakthimuthiah Mar 19 '14 at 07:14
  • @sathishkumar.challa Sorry, i don't know the way – Sakthimuthiah Oct 09 '14 at 06:32