can i get image file width and height from uri in android?
Blackbelt's answer is correct if you have a file uri. However, if you are using the new file providers as in the official camera tutorial, it won't work. This works for that case:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
getContext().getContentResolver().openInputStream(mPhotoUri),
null,
options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
private void getDropboxIMGSize(Uri uri){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(new File(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 memory. In fact BitmapFactory.decodeFile
will return null. In my example uri
is the phisical path to the image