Android piccaso缩放小图像以适应大图像视图,而不影响图像质量

Android piccaso缩放小图像以适应大图像视图,而不影响图像质量,android,android-imageview,picasso,Android,Android Imageview,Picasso,我见过许多缩小大图像并使其适合于小图像的例子。但我这里的问题是,如何在不损失图像质量的情况下增加图像的大小以适应特定的高度。下面是我尝试实现的代码: [![Picasso.with(context).load(context.getResources().getString(R.string.host) + aiAndroidResponse.getImage_url()).into(new Target() { @Override

我见过许多缩小大图像并使其适合于小图像的例子。但我这里的问题是,如何在不损失图像质量的情况下增加图像的大小以适应特定的高度。下面是我尝试实现的代码:

  [![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屏幕上看到的模糊

如何在不损失图像质量的情况下增加图像大小以适合特定高度


这当然是不可能的。

如果图像像素太低,请增加图像像素并转换为.png格式