我可以从Android的URI的图像文件的宽度和高度? [英] can i get image file width and height from uri in android?

查看:1141
本文介绍了我可以从Android的URI的图像文件的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 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

这篇关于我可以从Android的URI的图像文件的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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