【发布时间】:2018-08-22 19:55:19
【问题描述】:
我见过很多缩小大图像并将其缩小到不小的示例。但我的问题是如何增加图像的大小以适应特定的高度而不损失其质量。以下是我尝试实现的代码:
[![Picasso.with(context).load(context.getResources().getString(R.string.host) + aiAndroidResponse.getImage_url()).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
//whatever algorithm here to compute size
float ratio = (float) bitmap.getHeight() / (float) bitmap.getWidth();
float heightFloat = ((float) role_image.getWidth()) * ratio;
final android.view.ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) role_image.getLayoutParams();
layoutParams.height = (int) heightFloat;
layoutParams.width = (int) role_image.getWidth();
role_image.setLayoutParams(layoutParams);
role_image.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});][1]][1]
下面是垂直线性布局的xml文件:
<ImageView
android:id="@+id/role_image"
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/profile_default" />
请看下图,这是在安卓屏幕上看到的模糊
【问题讨论】:
-
图像像素太低,增加图像像素并转换为.png格式
标签: android android-imageview picasso