How can I make circle GLSurfaceView on Videoview?

China☆狼群 提交于 2020-01-16 00:49:09

问题


I'm using camera recorder library for video recording it's use GLSurfaceView. In my layout on VideoView I overlay GLSurfaceView.

It's showing Circle shape when I overlay GLSurfaceView over ImageView

It's showing Square shape when I overlay GLSurfaceView over VideoView.

I have tried below code for making circle GLSurfaceView.

public class SampleGLView extends GLSurfaceView implements View.OnTouchListener {

private Path clippingPath;

public SampleGLView(Context context) {
    this(context, null);
}

public SampleGLView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOnTouchListener(this);
}

private TouchListener touchListener;

@Override
public boolean onTouch(View v, MotionEvent event) {
    final int actionMasked = event.getActionMasked();
    if (actionMasked != MotionEvent.ACTION_DOWN) {
        return false;
    }

    if (touchListener != null) {
        touchListener.onTouch(event, v.getWidth(), v.getHeight());
    }
    return false;
}

public interface TouchListener {
    void onTouch(MotionEvent event, int width, int height);
}

public void setTouchListener(TouchListener touchListener) {
    this.touchListener = touchListener;
}

@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);
} }

Is any one have idea how to solve it.

来源:https://stackoverflow.com/questions/59660335/how-can-i-make-circle-glsurfaceview-on-videoview

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