以前我使用过SurfaceView,可以通过以下方法使其透明化。我现在不使用SurfaceView。不要将其标记为重复。我知道如何使SurfaceView透明,现在我正在尝试将我的代码从SurfaceView迁移到GLSurfaceView。为了使屏幕透明,我尝试了以下方法:
public void clear() {
Constants.debugLog(TAG,"clear method called ");
Canvas canvas = null;
try {
canvas = getHolder().lockCanvas();
canvas.drawColor(Color.TRANSPARENT);
} catch (Exception e) {
Constants.debugLog(TAG,"clear() 1st try "+e.toString());
} finally {
try {
if (canvas != null) {
getHolder().unlockCanvasAndPost(canvas);
}
} catch (Exception e) {
Constants.debugLog(TAG,"clear() 2nd try "+e.toString());
}
}
}
但它不适用于我的自定义GLSurfaceView。由于GLSurfaceView是SurfaceView的子类,因此它应该可以解决这个问题。抛出以下异常
Exception locking surface
java.lang.IllegalArgumentException
at android.view.Surface.nativeLockCanvas(Native Method)
at android.view.Surface.lockCanvas(Surface.java:275)
at android.view.SurfaceView$4.internalLockCanvas(SurfaceView.java:823)
at android.view.SurfaceView$4.lockCanvas(SurfaceView.java:791)
at com.ringid.voicecall.video.VideoCallImageRenderView.clear(VideoCallImageRenderView.java:77)
at com.ringid.voicecall.OutgoingRingCallScreen.stopOwnVideoCall(OutgoingRingCallScreen.java:988)
at com.ringid.voicecall.OutgoingRingCallScreen.decideStart_or_stop_Video(OutgoingRingCallScreen.java:1090)
at com.ringid.voicecall.OutgoingRingCallScreen.onClick(OutgoingRingCallScreen.java:882)
at android.view.View.performClick(View.java:4856)
对这个问题的任何想法对我都有帮助。 目前我正从相机在GLSurfaceView上绘制图像。当我停止相机并使GLSurfaceView的可见性为GONE时,它仍然显示屏幕上的最后一帧。所以我需要做那个透明的