简体   繁体   English

打开预览时,摄像机视图上的Android SurfaceView覆盖不会显示

[英]Android SurfaceView overlay on camera view does not show when preview is on

I have a FrameLayout containing two SurfaceViews. 我有一个包含两个SurfaceViews的FrameLayout。 One of them will show the camera preview, and the other is a custom surface view I use for drawing. 其中一个将显示相机预览,另一个是我用于绘图的自定义表面视图。 Problem is the surface view does not show up. 问题是表面视图没有显示出来。 If I comment out the line where the camera starts preview, it does though, on the black background. 如果我注释掉相机开始预览的行,它会在黑色背景上显示。 This indicates me that the Surface view is positioned well, but I suspect that when the camera preview draws, something goes wrong. 这表明我的Surface视图定位良好,但我怀疑当相机预览绘制时出现问题。

The camera view: 相机视图:

public CameraView(Context context, AttributeSet a) {
    super(context, a);
    mHolder = getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

The custom view: 自定义视图:

public InclinaisonGauge(Context context, AttributeSet attrs) {
    super(context, attrs);
    getHolder().addCallback(this);
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    run = true;
    updateThread = new Thread()
    {
        public void run()
        {
            Canvas c = null;
            final SurfaceHolder inclHolder = getHolder();
            while (run) {
                try {
                    c = inclHolder.lockCanvas();
                    if(c!=null)
                    {
                        synchronized (inclHolder) {
                            onDraw(c);
                        }
                    }
                } finally {
                // do this in a finally so that if an exception is thrown
                // during the above, we don't leave the Surface in an
                // inconsistent state
                if (c != null) {
                    inclHolder.unlockCanvasAndPost(c);
                }
            }           
        }
    }
};

And I use this very simple draw method on the custom view to make sure it is not a framerate issue 我在自定义视图上使用这个非常简单的绘制方法,以确保它不是帧速率问题

public void doDraw(final Canvas canvas, final boolean bigSize, float daDirection)
{
    canvas.drawARGB(255, 255, 255, 255);
}

Has anyone experienced this? 有没有人经历过这个?

Thanks 谢谢

好吧,如果有其他人得到这个,解决方法是在surfaceView上调用它

this.setZOrderMediaOverlay(true);

I don't think SurfaceViews are intended to be used as an overlay, but it is possible to achieve this behavior. 我不认为SurfaceViews可以用作叠加层,但可以实现此行为。 What you have to do is when the SurfaceView class is created: 您需要做的是创建SurfaceView类时:

    setZOrderMediaOverlay(true);
    getHolder().setFormat(PixelFormat.TRANSPARENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM