在 Android 中使图像视图的垂直边缘变得模糊

发布于 2025-01-16 16:22:32 字数 1149 浏览 3 评论 0原文

我想设计一个包含图像视图和具有两种特殊效果的背景视图的布局。第一个是主图像视图被变换为向垂直边缘褪色,第二个是具有模糊效果的背景图像视图,如图像

here

我能够实现的结果

此处< /a>

我看到这篇帖子是我的第一个效果,目前正在使用它,但它做当我将手机更改为深色模式时不起作用,因此我没有得到完美的解决方案。

我能够实现的第二个特殊模糊效果与我想要实现的效果相差甚远。所需的模糊效果对不同深浅的颜色有一定的硬度,而我的模糊效果相当平滑。对于我的模糊效果,我使用下面的代码,并为我的图像使用 Fresco 库。

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl))
            .setPostprocessor(new IterativeBoxBlurPostProcessor(60)).build();

PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setOldController(backgroundImage.getController())
            .build();
backgroundImage.setController(controller);

任何人都可以建议我任何好的解决方案或任何好的库,或者一些可以帮助我实现我想要的目标的代码示例。

I would like to design a layout containing an imageview and a background view with two special effect. First is where the main imageview gets transformed with faded towards the vertical edges and second is a background imageview with a blurred effect like the image

here

The result that i am able to achieve

here

I saw this post for my first effect and currently using it, but it does not work when I change my phone into dark mode so I am not getting a perfect solution.

And the second special blur effect that i am able to achieve is far way different from what i want to achieve. The required blur effect has some hardness of the different shades of color and mine one is quite smooth. For my blur effect I am using the below code and I am using the library Fresco for my image.

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl))
            .setPostprocessor(new IterativeBoxBlurPostProcessor(60)).build();

PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setOldController(backgroundImage.getController())
            .build();
backgroundImage.setController(controller);

Can anyone please suggest me any good solution or any good library for it or some code sample that can help me to achieve what I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2025-01-23 16:22:32

这里需要注意的是,模糊背景是图像本身的延伸。因此,如果屏幕的左侧具有紫色色调,则左上角的模糊区域也将是紫色的。

您可以使用像 Blurry 这样的库,它会模糊屏幕内容,然后将其设置为背景。您可以控制所需的模糊量。

一旦获得模糊图像,请将其设置为容器布局的背景并将图片设置在前面,

例如:

val bitmap = Blurry.with(this)
  .radius(10) // make it more if you want the lue to be more
  .sampling(8)
  .capture(findViewById(R.id.right_bottom)).get() // get the view you want to blur
imageView.setImageDrawable(BitmapDrawable(resources, bitmap)) // set the value to the background

The point to note here is the blurred background is an extension of the image itself. So if the left side of the screen has a purple hue the blurred region at the top left will be purple as well.

YOu can use a library like Blurry where it blurs the contents of the screen and then set that as a background. You can control the amount of blur you want.

Once you get the blurred image set it as the background of the container layout and set the picture in front

eg:

val bitmap = Blurry.with(this)
  .radius(10) // make it more if you want the lue to be more
  .sampling(8)
  .capture(findViewById(R.id.right_bottom)).get() // get the view you want to blur
imageView.setImageDrawable(BitmapDrawable(resources, bitmap)) // set the value to the background
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文