Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Image Width and Height from URI

Tags:

android

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;
}
like image 456
user2423476 Avatar asked Oct 12 '25 06:10

user2423476


1 Answers

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.

like image 186
ataulm Avatar answered Oct 16 '25 05:10

ataulm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!