简体   繁体   English

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

[英]Android piccaso scale small image to fit large imageview without affecting the quality of image

I have seen many example of down scaling of large image and fit it inot small. 我已经看到了许多缩小大图像并使之适合inot small的示例。 But my issue here is how can i increase size of image to fit a specific height without losing its quality. 但是我的问题是如何在不损失图像质量的情况下增加图像大小以适合特定高度。 below is code which i have tried to implement: 以下是我尝试实现的代码:

  [![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]

below is xml file in linear layout vertical: 以下是垂直线性布局的xml文件:

 <ImageView
                android:id="@+id/role_image"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:src="@drawable/profile_default" />

please see the below image from this is seen blur in android screen 请从下面的图像中看到下面的图像在android屏幕中看到模糊

在此处输入图片说明

how can i increase size of image to fit a specific height without losing its quality 我如何在不损失图像质量的情况下增加图像尺寸以适合特定高度

That is of course impossible. 那当然是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM