获取位图宽度和高度而不加载到内存 [英] Get bitmap width and height without loading to memory
问题描述
我是android的新手,所以我想知道有没有办法在不将位图加载到内存中的情况下获取位图的尺寸.??
Im a newbie in android, So i would like to know is there any way to get the dimensions of a Bitmap without loading the bitmap into memory.??
推荐答案
你可以通过 inJustDecodeBounds 设置 BitmapFactory.Options 来获取图片的宽高,而无需在内存中加载位图像素
You can set the BitmapFactory.Options with inJustDecodeBounds to get the image width and height without loading the bitmap pixel in memory
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
public boolean inJustDecodeBounds
因为:API 级别 1 如果设置为 true,解码器将返回 null(无位图),但 out... 字段将仍然被设置,允许调用者查询位图而无需为其像素分配内存.
Since: API Level 1 If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
这篇关于获取位图宽度和高度而不加载到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!