蒙版和剪辑GLSurfaceView [英] Mask and Clip GLSurfaceView
问题描述
我使用的SDK通过回调提供了矩形glsurfaceview.
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
我尝试使用掩膜版式,例如使用可蒙版版式 https://github.com/christophesmet/android_maskable_layout (适用于图像,不适用于视频)
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目标:**
**UI Objective : **
推荐答案
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.
然后在FrameLayout子类中使用canvas.clipPath:
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);
}
这篇关于蒙版和剪辑GLSurfaceView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!