Search code examples
androiduniversal-image-loader

Get image width and height before loading them


I'm using Universal Image Loader library to download my images from internet.

Is it possible to get images size before loading them to set my layout prams to desired values?

Something like inJustDecodeBounds property, Any ideas?


Solution

  • Quoting from the documentation @ https://github.com/nostra13/Android-Universal-Image-Loader

    How UIL define Bitmap size needed for exact ImageView? It searches defined parameters?

    1. Get actual measured width and height of ImageView.

    2. Get android:layout_width and android:layout_height parameters.

    3. Get android:maxWidth and/or android:maxHeight parameters.

    4. Get maximum width and/or height parameters from configuration (memoryCacheExtraOptions(int, int) option).

    5. Get width and/or height of device screen.

    So try to set android:layout_width|android:layout_height or android:maxWidth|android:maxHeight parameters for ImageView if you know approximate maximum size of it. It will help correctly compute Bitmap size needed for this view and save memory.

    You cannot get the image height and width before the image is downloaded. You can set the imageview height and width.