在拍摄照片之前,如何获得将通过 Android 相机拍摄的照片的默认大小(以像素为单位)?

How can I get the default size (in pixels) of a photo which will be captured through Android camera, before capturing it?

如果它是由 Android 设备屏幕的分辨率决定的,有没有办法以编程方式获取该分辨率的值?

你可以这样做

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;

更新:

您可以使用显示指标让您的屏幕具有

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

int width = metrics.widthPixels;
int height = metrics.heightPixels;

注意:您的屏幕分辨率和相机分辨率可能不同。请参考answer here.

使用以下代码段获取屏幕尺寸。 this 表示当前 Activity 上下文。

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;

If it is determined by the resolution of the Android device's screen

没有

How can I get the default size (in pixels) of a photo which will be captured through Android camera

没有"default size... of a photo".

如果您自己使用 android.hardware.Cameraandroid.hardware.camera2 API,则需要从可用分辨率中指定所需的分辨率。

如果您使用 ACTION_IMAGE_CAPTURE,分辨率将部分取决于您是否通过 EXTRA_OUTPUT,否则取决于相机应用程序。有数千种 Android 设备型号,预装了数百种不同的相机应用程序,还有许多其他相机应用程序可通过 Play 商店等分销渠道获得。他们将使用 android.hardware.Cameraandroid.hardware.camera2 API,并且他们将通过他们想要的任何算法选择他们想要使用的分辨率。