【问题标题】:Android piccaso scale small image to fit large imageview without affecting the quality of imageAndroid piccaso 缩放小图像以适应大图像视图而不影响图像质量
【发布时间】: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


【解决方案1】:

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

这当然是不可能的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 2016-06-17
    相关资源
    最近更新 更多