【问题标题】:Blur effect on background背景模糊效果
【发布时间】:2017-07-17 03:51:03
【问题描述】:

我需要在 ImageView 中显示类似的内容

你知道像这样在 ImageView 中设置图像的方法吗?

背景图片偏蓝,上面的图片有模糊效果

ImageView imageView=(ImageView)findViewById(R.id.imageView2);
imageView.setImageBitmap(bitmap);

我需要在位图中放入我的图片和背景模糊图片。

这只设置了一张图片,我需要放一些模糊的背景

我知道如何仅将一张图片设为 100% 质量。
但我不知道如何将背景图像设置为这张图片。

我不知道这个“过滤器”名称是如何产生的,我也无法通过谷歌搜索。

为什么投反对票?我不知道如何改进我的问题。

【问题讨论】:

  • 你的问题有点不清楚你想达到什么目的再次在一行中提及
  • 您想要模糊背景图像。这就是您需要搜索的全部内容。
  • 谢谢我会试试..
  • 顺便说一句,如果你不知道英文的单词是什么,请用谷歌搜索word_in_your_language in english
  • 我不知道我的语言是怎么写的 :)

标签: android image


【解决方案1】:

来自https://stackoverflow.com/a/36193733

我最近遇到了 Renderscript API。

//Set the radius of the Blur. Supported range 0 < radius <= 25
private static final float BLUR_RADIUS = 25f;

public Bitmap blur(Bitmap image) {
if (null == image) return null;

Bitmap outputBitmap = Bitmap.createBitmap(image);
final RenderScript renderScript = RenderScript.create(this);
Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

//Intrinsic Gausian blur filter
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
} 

在图像视图中使用上面的代码sn-p,如下所示。

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.nature);
Bitmap blurredBitmap = blur(bitmap);
imageView.setImageBitmap(blurredBitmap);

不要忘记在 build.gradle 文件中添加以下行

renderscriptTargetApi 18
renderscriptSupportModeEnabled true

【讨论】:

【解决方案2】:

您可以在每个页面中使用 View Pager 和 Add ImageView,这样您就可以在图像之间切换,

【讨论】:

  • 不,这个问题与它无关..我找不到好的图片..只有这个:)我需要在同一个图像视图上的背景图片和模糊图片
【解决方案3】:

使用

将您的模糊/模糊图像设置为背景
     android:background = "@drawable/myFuzzyImage"

像往常一样使用 setImageBitmap 或在活动布局的 xml 文件中使用 ImageView 设置清晰的图像。

【讨论】:

  • 以及如何从我的图像中构建模糊图像?
  • 将图像添加到您的可绘制文件夹。在活动的主布局中,.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 2021-11-12
相关资源
最近更新 更多