I'd like to use camera resolution of both front and rear in my activity so that i can distinguish an image (whether taken from back or front camera by checking its resolution).
Asked
Active
Viewed 3,235 times
0
-
This could help you http://stackoverflow.com/questions/19463858/how-to-get-front-and-back-cameras-megapixel-that-is-designed-for-android-device . – katmanco Nov 14 '16 at 14:31
-
not helping ........ because Camera is depreciated. – rohit singh Nov 14 '16 at 14:37
-
Ok but have not they put anything else instead of Camera ? Normally when anything depreciated it is replaced with new and more robust things. – katmanco Nov 14 '16 at 14:39
-
yes they putted a whole library i.e., cameraManager but i can't find out any specific method for my purpose in this documentation https://developer.android.com/reference/android/hardware/camera2/package-summary.html – rohit singh Nov 14 '16 at 14:42
1 Answers
1
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();

MonkeyEdict
- 11
- 1
-
ya but it is showing camera object as depreciated resulting in " Unfortunately activity has stopped working " – rohit singh Nov 14 '16 at 14:32
-
https://developer.android.com/reference/android/hardware/camera2/package-summary.html – MonkeyEdict Nov 14 '16 at 14:36
-
-
could you tell specific method to do this job because i can't find out any related method in the documentation for my purpose. – rohit singh Nov 14 '16 at 14:38