我可以通过 MediaStore.Images.Media
获取图像的宽度一般
但我需要得到从下拉框选择该图像的宽度和高度,从图像
所以目前我有如下的方法来获取图像大小的保管箱
私人无效getDropboxIMGSize(URI URI){
字符串的大小= Long.toString(新文件(uri.getPath())长());
返回的大小;
}
但我真正需要的是得到该文件的宽度和高度值
谁知道如何做到这一点?请大家帮帮忙!
解决方案 私人无效getDropboxIMGSize(URI URI){
BitmapFactory.Options选项=新BitmapFactory.Options();
options.inJustDe codeBounds = TRUE;
BitmapFactory.de codeFILE(uri.getPath())getAbsolutePath(),选件)。
INT imageHeight = options.outHeight;
INT ImageWidth等= options.outWidth;
}
没有也没办法。你必须创建一个位图对象。如果您使用 inJustDe codeBounds
标志momery位图就不会被加载。事实上 BitmapFactory.de codeFILE
将返回null。在我的例子 URI
是物理性的图像的路径
i can getting the image width through MediaStore.Images.Media
normally
but i need to getting the image width and height from image which selected from dropbox
so currently i have following method to getting image size from dropbox
private void getDropboxIMGSize(Uri uri){
String size = Long.toString(new File(uri.getPath()).length());
return size;
}
but what i actually need are getting the file width and height value
anyone know how to achieve that?please help!
解决方案private void getDropboxIMGSize(Uri uri){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(uri.getPath()).getAbsolutePath(), options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
}
no there is no way. You have to create a Bitmap object. if you use the inJustDecodeBounds
flag the bitmap would not be loaded in momery. In fact BitmapFactory.decodeFile
will return null. In my example uri
is the phisical path to the image