获取位图宽度和高度而不加载到内存 [英] Get bitmap width and height without loading to memory

查看:19
本文介绍了获取位图宽度和高度而不加载到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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.

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

这篇关于获取位图宽度和高度而不加载到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆