机器人:获取图像的尺寸,而无需打开它机器人、图像、尺寸

2023-09-03 21:17:08 作者:安稳一人

我想获得的宽度和高度(以像素为单位),其存储在SD卡的图像,它们加载到RAM之前。我需要知道的大小,这样我就可以加载它们时,相应的下采样它们。如果没有下采样他们,我得到一个OutOfMemoryException。

I want to get width and height (in pixels) of images which are stored on the sdcard, before loading them into RAM. I need to know the size, so I can downsample them accordingly when loading them. Without downsampling them I get an OutOfMemoryException.

任何人都知道如何得到的图像文件的尺寸?

Anyone knows how to get dimensions of image files?

推荐答案

传递选项C的范围到工厂只需去$ C $:

Pass the option to just decode the bounds to the factory:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

//Returns null, sizes are in the options variable
BitmapFactory.decodeFile("/sdcard/image.png", options);
int width = options.outWidth;
int height = options.outHeight;
//If you want, the MIME type will also be decoded (if possible)
String type = options.outMimeType;

心连心