Android BlurMaskFilter has no effect in canvas.drawOval while text is blurred

后端 未结 3 1759
感情败类
感情败类 2020-12-01 03:16

I\'ve been trying to create a custom view which has blurred shapes under text. The problem is that the BlurMaskFilter has no effect on any shape that I draw on the canvas. H

相关标签:
3条回答
  • 2020-12-01 03:27

    Looks like a bug to me. I reported it to the Android team; we'll see what they say.

    It renders correctly if you set android:hardwareAccelerated="false" on your Activity in AndroidManifest.xml.

    Here is the official word from the Android graphics team: "BlurMaskFilter is not supported with hardware acceleration." (As of July 10, 2012)

    0 讨论(0)
  • 2020-12-01 03:37

    If you can not disable hardware acceleration in your activity (for example it uses TextureView which require hardware acceleration) you can just call setLayerType with first parameter LAYER_TYPE_SOFTWARE and the second parameter null for your view.

    Like this

    public class BlurTestView extends View {
    
        public BlurTestView(Context context) {
            this(context, null, 0);
        }
    
        public BlurTestView(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
    
        public BlurTestView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
    
            // Disable hardware acceleration for this view
            setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
    
            // Perform other initialisation 
        }
    
        // Other methods and so on...
    }
    

    More info about mask filters, effects and shaders you can find here.

    0 讨论(0)
  • 2020-12-01 03:41

    I had the same issue while adding a filter to a path. I noticed that setting the target to 13 or below allows the filters to work. 14 and up they didn't.

    android:targetSdkVersion="13" 
    
    0 讨论(0)
提交回复
热议问题