我正在使用滑行将图像加载到recyclerview中的图像视图中 但对于低分辨率手机图像变得扭曲,因为在浏览器中打开时相同的图像可以正确显示
它可以在高端手机中正常使用
以下是我的代码
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);
}
});
在写入的文本中略有失真
缩放图片有问题吗?
答案 0 :(得分:0)
尝试此解决方案
@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);
}
使用矩阵调整大小。