如何在Android/Java中获得Image的分辨率

CoD*_*oDe 5 android

如何在Android中找到任何图像的分辨率?

Har*_*h_N 11

获取存储在磁盘中的图像大小的有效方法(例如,获取用户选择用于上载的图像文件的大小)是使用BitmapFactory.Options并设置inJustDecodeBounds为true.通过这样做,您将获得图像文件的大小(宽度和高度),而无需将整个图像加载到内存中.当想要在上传之前检查图像的分辨率时,这将有所帮助.

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;
Run Code Online (Sandbox Code Playgroud)


Geo*_*rge 5

如果您的图像位于res/drawable上,您可以使用以下内容:

Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back);
bmp.getWidth(), bmp.getHeight();
Run Code Online (Sandbox Code Playgroud)


Rat*_*ley 5

我想你正在寻找这个...

bitmap=MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);

int imageWidth=bitmap.getWidth();

int imageHeight=bitmap.getHeight();
Run Code Online (Sandbox Code Playgroud)

尝试使用它,让我知道