机器人:获取图像的尺寸,而无需打开它 [英] android: get image dimensions without opening it

查看:143
本文介绍了机器人:获取图像的尺寸,而无需打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的宽度和高度(以像素为单位),其存储在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;

心连心

这篇关于机器人:获取图像的尺寸,而无需打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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