Android piccaso 缩放小图像以适应大图像视图而不影响图像质量
Android piccaso scale small image to fit large imageview without affecting the quality of image
我见过很多缩小大图像并使其不适合小图像的例子。但我的问题是如何在不损失质量的情况下增加图像的大小以适应特定的高度。下面是我试图实现的代码:
[![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" />
请看下图 android 屏幕
how can i increase size of image to fit a specific height without losing its quality
那当然不可能。
我见过很多缩小大图像并使其不适合小图像的例子。但我的问题是如何在不损失质量的情况下增加图像的大小以适应特定的高度。下面是我试图实现的代码:
[![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" />
请看下图 android 屏幕
how can i increase size of image to fit a specific height without losing its quality
那当然不可能。