获取位图的宽度和高度,而无需装载到内存 [英] Get bitmap width and height without loading to memory

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

问题描述

林在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.??

推荐答案

您可以设置inJustDe codeBounds的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();

有关详细信息:

公共布​​尔inJustDe codeBounds

public boolean inJustDecodeBounds

自:API级别1如果设置为true,   去codeR将返回null(没有位图),但出...字段将   仍然被设置,使得主叫用户查询位图,而不必   分配内存为它的像素。

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.

<一个href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDe$c$cBounds">http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDe$c$cBounds

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

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