Android draw with blur

那年仲夏 提交于 2019-11-29 10:55:18

问题


I need do draw on Android's Canvas using Blur effect, it is a very simple feature, I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent.. any ideas?


回答1:


(For those who are coming back, though this is an old question)

On the Paint object which you are using to draw the Color, set

paint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL))

Then, in Android Manifest.xml, set

android:hardwareAccelerated="false"

for your activity (Blur doesn't work when hardware acceleration is true)

For more explanation refer Android BlurMaskFilter has no effect in canvas.drawOval while text is blurred




回答2:


If you're not gonna need to manipulate it afterwards you could just draw to a buffer and blur it yourself pixel by pixel, then blit that buffer to screen when you need to paint it.

Or this: http://developer.android.com/reference/android/graphics/BlurMaskFilter.Blur.html




回答3:


Take a look at this: Android, Blur Bitmap instantly?

Again I would recommend you first to draw into a bitmap. Scale it down (try different sizes), and the scale it back up to the original size (either as a new bitmap or if you use hw acceleration do it while you draw).



来源:https://stackoverflow.com/questions/1979955/android-draw-with-blur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!