【问题标题】:Image not getting blur as well as not stretched图像没有变得模糊,也没有拉伸
【发布时间】:2017-12-22 07:28:26
【问题描述】:

我想做这样的事情

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

这是我的代码

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

BlurTransformation.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";
    }
}

我无法在这种尺寸的图像上得到我想要的结果 我懂了

【问题讨论】:

  • 你能贴出图片来说明你的实际结果吗?
  • @Hai Hack 请检查我编辑的答案
  • 请包含xml文件
  • 使宽度匹配父项
  • 为什么不以编程方式拒绝它?

标签: android picasso uiblureffect


【解决方案1】:

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

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

【讨论】:

  • 我使用 centercrop 比我没有得到完美的图像图像的头部将被隐藏
【解决方案2】:

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

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

在此处检查 scaleType 的其他选项:

【讨论】:

  • 请参考我的图像 我希望图像水平拉伸并适合水平居中。因为我的图像的宽度与高度相比并不多
  • @NiravJoshi 在这种情况下,使用 fitXY
猜你喜欢
  • 2013-09-20
  • 1970-01-01
  • 2021-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 2017-06-06
  • 1970-01-01
相关资源
最近更新 更多