简体   繁体   English

RenderScript“慢速”模糊

[英]RenderScript “slow” blur

I've been fiddling around with RenderBlur on an image for my login screen, i've gotten everything to work with a runnable() and a delay to blur the image immediately, however i'm trying to make it a slow blur while the username and password fields come into view. 我一直在为登录屏幕上的图像上摆弄RenderBlur,我已经将所有内容与runnable()一起使用,并延迟了立即模糊图像,但是我正在尝试使其缓慢模糊,同时用户名和密码字段会出现。

I've had a bit of a look around (could be looking in the wrong places) but I haven't found anything related to what i'm after. 我环顾了一下(可能在错误的位置),但是我没有找到与所追求的东西相关的任何信息。 I've attempted to use a while loop and have a blurradius value increment with a delay afterwards and send to the blurBitmap class method, but it either still blurs it immediately (meaning I probably messed something up somewhere and will most likely keep trying with this method until a better solution is found).. or it crashes. 我尝试过使用while循环,然后将带有一个radiusradius的值增加一个延迟,然后发送给blurBitmap类方法,但是它要么仍然立即使它模糊(这意味着我可能在某个地方弄乱了某些东西,并且很可能会继续尝试此操作)方法,直到找到更好的解决方案为止)。否则它就会崩溃。

Does anyone know if, in the first place this is possible with RenderScript? 有谁知道,首先使用RenderScript是否可以实现? And if so, what should I be searching for. 如果是这样,我应该寻找什么。

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

Resources: https://futurestud.io/blog/how-to-use-the-renderscript-support-library-with-gradle-based-android-projects 资源: https : //futurestud.io/blog/how-to-use-the-renderscript-support-library-with-gradle-based-android-projects

You can do this with RenderScript, though how you are doing it now doesn't sound like a good idea. 您可以使用RenderScript进行此操作,尽管您现在的操作听起来似乎不是一个好主意。 Look into using a custom Animator which you can then run a RS blur against the image. 研究使用自定义Animator ,然后可以对图像运行RS模糊。 Using Animator will be more flexible in the long run and automatically ties in with the view system rather than requiring you to handle View or Activity state explicitly. 从长远来看,使用Animator会更灵活,并且可以自动与视图系统联系,而不是要求您显式处理ViewActivity状态。

The approach @JasonWihardja outlined will also work, but again I would suggest doing this in an Animator or similar mechanism. @JasonWihardja概述的方法也可以使用,但是我还是建议使用Animator或类似机制进行此操作。

Blurring an image repeatedly might cause some performance issues with your app. 反复模糊图像可能会导致应用程序出现一些性能问题。

Here's what you could do: 您可以执行以下操作:

  1. Arrange 2 images (1 for the clear image and the other for the maximum blur version) so that the blur image is placed exactly on top of the clear image. 排列2张图像(1张为清晰图像,另一张为最大模糊版本),以便将模糊图像准确放置在清晰图像的顶部。 The easiest way would be placing 2 ImageView s in a FrameLayout 最简单的方法是将2 ImageView放置在FrameLayout
  2. To achieve the "slow" blur effect, initially set the blur image's alpha to 0. 要实现“慢速”模糊效果,请首先将模糊图像的alpha设置为0。
  3. Then, using one of the view, issue a postDelayed event to slowly increase the blur image's alpha to 255. 然后,使用其中一个视图,发出一个postDelayed事件,以将模糊图像的alpha缓慢增加到255。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM