【发布时间】:2020-05-31 04:30:29
【问题描述】:
我使用 Jsoup 来阅读网站。但在 html 中,并非所有图像都有大小信息。所以,如果它不存在,我想以其他方式找出图像大小,使用图像源 URL。
【问题讨论】:
-
下载图片,然后使用
BitmapFactory读取尺寸。
标签: java android image jsoup image-size
我使用 Jsoup 来阅读网站。但在 html 中,并非所有图像都有大小信息。所以,如果它不存在,我想以其他方式找出图像大小,使用图像源 URL。
【问题讨论】:
BitmapFactory读取尺寸。
标签: java android image jsoup image-size
我建议使用滑行
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
}
});
【讨论】: