Search code examples
androidandroid-imageviewpicasso

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. 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:

 <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

enter image description here


Solution

  • how can i increase size of image to fit a specific height without losing its quality

    That is of course impossible.