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)
如果您的图像位于res/drawable上,您可以使用以下内容:
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back);
bmp.getWidth(), bmp.getHeight();
Run Code Online (Sandbox Code Playgroud)
我想你正在寻找这个...
bitmap=MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
int imageWidth=bitmap.getWidth();
int imageHeight=bitmap.getHeight();
Run Code Online (Sandbox Code Playgroud)
尝试使用它,让我知道
| 归档时间: |
|
| 查看次数: |
8694 次 |
| 最近记录: |