图像不会变得模糊,也不会拉伸

问题描述 投票:-1回答:2

我想做这样的事情

enter image description here

我尝试使用Picaso但没有得到任何有价值的解决方案

在这里我的代码

String url ="http://static.tvtropes.org/pmwiki/pub/images/stephen_amell.png";
      Picasso.with(getActivity()).load(url)
                        .transform(new BlurTransformation(getActivity()))
                        .into(imgBlurImage);

blur transformation.Java

public class BlurTransformation implements Transformation {

    RenderScript rs;
    private static final int RADIUS = 10;

    public BlurTransformation(Context context) {
        super();
        rs = RenderScript.create(context);
    }

    @Override
    public Bitmap transform(Bitmap bitmap) {
        // Create another bitmap that will hold the results of the filter.
        Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

        // Allocate memory for Renderscript to work with
        Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL,
                Allocation.USAGE_SHARED);
        Allocation output = Allocation.createTyped(rs, input.getType());

        // Load up an instance of the specific script that we want to use.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setInput(input);
            // Set the blur radius
            script.setRadius(RADIUS);
            // Start the ScriptIntrinisicBlur
            script.forEach(output);
        }
        // Copy the output to the blurred bitmap
        output.copyTo(blurredBitmap);
        bitmap.recycle();
        return blurredBitmap;
    }

    @Override
    public String key() {
        return "blur";
    }
}

我无法在这个尺寸的图像上得到我想要的结果我得到了这个enter image description here

android picasso uiblureffect
2个回答
2
投票

图像模糊。它的图像视图没有完美的比例类型。使用android:scaleType="centerCrop"进行图像查看。

  <ImageView
         android:id="@+id/img_2"
         android:layout_width="match_parent"
         android:layout_height="200dp"
         android:scaleType="centerCrop" />

1
投票

如果您不想隐藏头部,请将fitStart设置如下。

<ImageView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:scaleType="fitStart" />

在这里检查scaleType的其他选项:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.