16

我是android的新手,所以我想知道有没有办法在不将位图加载到内存的情况下获取位图的尺寸。??

4

1 回答 1

33

您可以使用 inJustDecodeBounds 设置 BitmapFactory.Options 以获取图像宽度和高度,而无需将位图像素加载到内存中

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, bitmapOptions);
int imageWidth = bitmapOptions.outWidth;
int imageHeight = bitmapOptions.outHeight;
inputStream.close();

更多细节:

公共布尔 inJustDecodeBounds

自:API 级别 1 如果设置为 true,解码器将返回 null(无位图),但 out... 字段仍将设置,允许调用者查询位图而无需为其像素分配内存。

http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds

于 2012-07-27T04:13:33.600 回答