maksonnie
maksonnie

Reputation: 743

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.

Upvotes: 0

Views: 4685

Answers (2)

Mhammed Khaled
Mhammed Khaled

Reputation: 89

/*this library*/

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

/* this code */

Glide.with(this)
            .asFile()     // get size image url
            .load("link image url")
            .into(new SimpleTarget<File>() {
                @Override
                public void onResourceReady(@NonNull File resource, @Nullable 
                    Transition<? super File> transition) {
                    fab_full.setLabelText(""+resource.length());     //  /1024 kb
                }
            });

Upvotes: 0

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) {
            }
        });

Upvotes: 3

Related Questions