2015-03-03 42 views
1

我使用通過回調提供矩形glsurfaceview的SDK。面具和剪輯GLSurfaceView

我希望能夠以圓形佈局呈現此視圖。 (IE),我想在一個圓形視圖顯示視圖

我一直在使用屏蔽佈局嘗試,如使用可屏蔽佈局https://github.com/christophesmet/android_maskable_layout(偉大工程的圖像,沒有那麼多視頻)

我如何去裁剪並將其渲染爲一個圓圈?

(背景是不斷變化的,所以我不能疊加在該視頻視圖的頂部上的透明視圖,其目的是爲具有在頂部的矩形glsurface視圖其中有一個圓形glsurface視圖)

* * UI目標:** enter image description here

+0

我不是很確定你想要的佈局的樣子,或者你的應用程序是如何構成的。您可以使用第二個SurfaceView創建遮罩層;您只需要爲遮罩層設置更近的Z深度。如果您有權訪問視頻源,則可以將其指向SurfaceTexture,然後使用自定義着色器來修改渲染(例如,對於每個片段,計算與中心的距離,並且如果它位於圓圈外部,則呈現爲透明黑色)。有關各種示例,請參閱Grafika(https://github.com/google/grafika)。 – fadden 2015-03-03 17:02:06

+0

@fadden編輯帖子以添加UI的外觀圖像。不會有這可能表面是一個問題?我無法訪問視頻源 - 這是一個連續的實時視頻流。謝謝你的領導,我會檢查grafika。 – lavi 2015-03-05 04:01:01

回答

0

我現在有一個幾乎與項目相同的要求,其中涉及掩蓋由PexKit提供的GLSurfaceView。適用於我的解決方案是製作FrameLayout(或任何其他ViewGroup)的子類,並將GLSurfaceView放入其中。

然後在子類中的FrameLayout使用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); 
}