If it is determined by the resolution of the Android device's screen, is there a way to programatically get the value of that resolution?
3 Answers
If it is determined by the resolution of the Android device's screen
No.
How can I get the default size (in pixels) of a photo which will be captured through Android camera
There is no "default size... of a photo".
If you are using the android.hardware.Camera
or android.hardware.camera2
APIs yourself, you need to specify the resolution that you want, from the available resolutions.
If you are using ACTION_IMAGE_CAPTURE
, the resolution will be based in part on whether you pass EXTRA_OUTPUT
or not, but otherwise is up to the camera app. There are thousands of Android device models, shipping with hundreds of different pre-installed camera apps, and there are many other camera apps available through distribution channels like the Play Store. They will be using the android.hardware.Camera
or android.hardware.camera2
APIs, and they will choose what resolution they want to use, by whatever algorithm they want.

- 986,068
- 189
- 2,389
- 2,491
you can do like this
String pickedImagePath = "path/of/the/selected/file";
BitmapFactory.Options bitMapOption=new BitmapFactory.Options();
bitMapOption.inJustDecodeBounds=true;
BitmapFactory.decodeFile(pickedImagePath, bitMapOption);
int imageWidth=bitMapOption.outWidth;
int imageHeight=bitMapOption.outHeight;
Update:
you can use display metrics to get your screen with
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
Note: The resolution of your screen and resolution of camera may not be the same. please refer the answer here.

- 1
- 1

- 3,338
- 1
- 20
- 44
-
Thank you, but I am sorry may be my question was not clear enough. I just edited the question statement. I meant to ask that I need the resolution even before the image is captured. Infact what I am after is the number of pixels (i.e. width and height of screen showing the live camera feed in pixels) of the live camera feed? – Solace Jul 23 '16 at 17:05
-
1you want get the screen width and height in pixels, am i right? – SaravInfern Jul 23 '16 at 17:09
-
Yes if the width and height of a camera frame in a full screen live camera feed is the same as the screen width and height? – Solace Jul 23 '16 at 17:15
-
1Thank you so much for your answer and time. I had to accept the other one since that was more clear and comprehensive. But I upvoted a couple other good answers by you as a token of thanks. – Solace Jul 23 '16 at 17:57
-
1@Solace: No problem, I have provided the answer link from commonsware answer only – SaravInfern Jul 23 '16 at 18:14
Get the screen size using the following snippet. this
means the current Activity context.
WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;

- 440
- 2
- 10