如果我知道它的 URL 如何获取图像大小? Android (java)

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

我用Jsoup 看网站。但在 html 中,并非所有图像都有尺寸信息。所以,如果它不存在,我想以其他方式找出图像大小,使用图像源 URL。

我建议使用 glide

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

然后使用 glide

加载图像 url
        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) {
            }
        });
/*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
                }
            });