Android 获取图片原始宽高 并设置比例
程序员文章站
2022-06-21 15:02:13
...
Glide.with(mViewBinding.iv)
.load(url)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
Bitmap bitmap = ImageUtils.drawable2Bitmap(resource);
int height = bitmap.getHeight();
int width = bitmap.getWidth();
System.out.println(" height : " + height);
System.out.println(" width : " + width);
//宽是屏幕宽 高是比例
int screenWidth = ScreenUtils.getScreenWidth();
mViewBinding.iv.getLayoutParams().width = screenWidth;
mViewBinding.iv.getLayoutParams().height = screenWidth * height / width;
mViewBinding.iv.setImageBitmap(bitmap);
}
});
Glide.with(mViewBinding.iv)
.asBitmap()
.load(url)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
int height = bitmap.getHeight();
int width = bitmap.getWidth();
//宽是屏幕宽 高是比例
int screenWidth = ScreenUtils.getScreenWidth();
mViewBinding.iv.getLayoutParams().width = screenWidth;
mViewBinding.iv.getLayoutParams().height = screenWidth * height / width;
mViewBinding.iv.setImageBitmap(bitmap);
}
});