Search code examples
javaandroidimagejsoupimage-size

How to get image size if I know its URL? Android (java)


I use Jsoup to read the website. But in html not all images have size information. So, if it is not there, I want to find out the image size in some other way, using the image source URL.


Solution

  • I would suggest use glide

    dependencies {
      implementation 'com.github.bumptech.glide:glide:4.11.0'
      annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    }
    

    and then load your image url using glide

            Glide.with(this)
            .asBitmap()
            .load(path)
            .into(new CustomTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    int width = bitmap.getWidth();
                    int height = bitmap.getHeight()
                }
    
                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });