Is it possible to get the width and height of a image file from its URI. I was trying to use this code but theirs a error: has a syntax error after the getAbsolutePath()
Syntax error on token ")", invalid ArgumentList
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;
}
If you extract your arguments into local variables, you'll be less likely to miss a parenthesis/include an extra one, and it'll be easier to read your code.
Before:
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;
}
After:
private void getDropboxIMGSize(Uri uri){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
String path = uri.getPath().getAbsolutePath();
BitmapFactory.decodeFile(path, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
}
Note, you've assigned options.outHeight
and options.outWidth
to local variables and then the method ends; you're not doing anything with these values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With