Mask and Clip GLSurfaceView

大憨熊 提交于 2019-12-08 03:09:56

问题


I work with an SDK that provides a rectangular glsurfaceview through a callback.

I want to be able to render this view in a circular layout. (i.e.) I would like to display the view on a circular view

I have tried using masking layout such as using a maskable layout https://github.com/christophesmet/android_maskable_layout (works great for images, not so much for videos)

How do I go about clipping and rendering this as a circle?

(The background is constantly changing, so i cant overlay a transparent view on top of this video view. The aim is to have a rectangular glsurface view on top of which there is a circular glsurface view)

**UI Objective : **


回答1:


I have pretty much the same requirement with a project right now, which involves masking a GLSurfaceView provided by PexKit. The solution that works for me is making a subclass of FrameLayout (or any other ViewGroup) and placing the GLSurfaceView inside it.

Then in the FrameLayout subclass use canvas.clipPath:

private Path clippingPath;

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (w != oldw || h != oldh) {
        int radius = Math.min(w, h)/2;
        clippingPath = new Path();
        clippingPath.addCircle(w/2, h/2, radius, Path.Direction.CW);
    }
}

@Override
protected void dispatchDraw(Canvas canvas) {
    int count = canvas.save();
    canvas.clipPath(clippingPath);
    super.dispatchDraw(canvas);
    canvas.restoreToCount(count);
}


来源:https://stackoverflow.com/questions/28830469/mask-and-clip-glsurfaceview

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