我正在使用 glide 将图像加载到 recyclerview 中的 ImageView 中 但是对于低分辨率手机图像会失真,而在浏览器中打开时可以正确看到相同的图像
它在高端手机上正常工作
下面是我的代码
Glide.with(context).load(url).apply(requestOptions).
into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable drawable, Transition<? super Drawable> transition) {
BitmapDrawable bd = (BitmapDrawable) drawable;
int width = bd.getBitmap().getWidth();
int height = bd.getBitmap().getHeight();
int phoneWidth = PhoneUtils.getScreenWidth(context);
float phW = phoneWidth;
float wid = width;
float factor = phW / wid;
double h = factor * height;
height = (int) Math.ceil(h);
width = phoneWidth;
Bitmap bitmap = Bitmap.createScaledBitmap(bd.getBitmap(), width, height, false);
imageView.setImageBitmap(bitmap);
}
});
书写的文字略有失真
图片缩放有问题吗?
最佳答案
试试这个解决方案
@Override
public void onResourceReady(Drawable drawable, Transition<? super Drawable> transition) {
BitmapDrawable bd = (BitmapDrawable) drawable;
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
int phoneWidth = PhoneUtils.getScreenWidth(context);
float phW = phoneWidth;
float wid = width;
float factor = phW / wid;
Matrix matrix = new Matrix();
matrix.postScale(factor, factor);
Bitmap bitmap = Bitmap.createBitmap(bd.getBitmap(), 0, 0,
width, height, matrix, true);
imageView.setImageBitmap(bitmap);
}
使用矩阵调整大小。
关于android - 图像在滑动缩放时失真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48258453/