Open izackp opened 2 years ago
How do you imagine this can be fixed?
You have a bitmap with View snapshot, let's say 100x100, pure white. Blurring it produces a pure white bitmap again.
Next frame, the top 1-2 rows of pixels become red. You blur this bitmap with a radius of 20 pixels, and the red color spreads down by 20 pixels give or take.
The effect is then exaggerated because of the need to downscale the original bitmap to produce the blur in a reasonable amount of time. Blurring a full-sized bitmap would help to mitigate this by a large amount, but most of budget+ Android devices would choke on that
Hmm I thought about two ways but they both seem like a pain
Capture a larger bitmap lets say its 100x100 and the radius is 20 pixels create a blur that's 140x140 then clip the 100x100 image out of that. However, I don't really like the idea of having the blur change color before an image gets under it.
Weighting the blur radius based on distance from an edge Maybe capping the radius blur per pixel based on it's distance from an edge. 1px away = 1 px max radius In a 100x100 with a 20 blur radius, all items inside of (20,20 - 60x60) will blur as usually and any outside will be weighted down by radius and perhaps intensity?
Both don't really seem like easy fixes tho, since you're using a built-in algorithm to do the blurring.
However, I don't really like the idea of having the blur change color before an image gets under it.
Yes, it's a fundamental problem of this kind of approach
Weighting the blur radius based on distance from an edge
While it might seem like a remedy for this particular case, it will produce weird/incorrect results in general.
To really fix this the BlurView needs to stop downscaling the view hierarchy to speed up the blur, but with all the limitations Android imposes, that's just not realistic for weaker devices.
Thanks for the suggestions though!
This is somewhat addressed for API >= 31 in version 2.0.0 with the new RenderEffectBlur
.
It's still not ideal, also barely tested, but you can try it out
Let's say you have a blue background with a red rectangle moving. Once the red rectangle reaches the blue view then moves 1 pixel underneath it BAM the whole area is now has a red tint. High contrast elements will flash in and out as the user scrolls which become noticeable.
https://gfycat.com/fatalgroundedjanenschia