Invisible SurfaceView for Camera Preview

后端 未结 2 1937
Happy的楠姐
Happy的楠姐 2020-12-18 01:58

I need to get camera preview data only, but not visible preview. Since I\'m doing all this in a service, I had to create a dummy SurfaceView, which works very well.

相关标签:
2条回答
  • 2020-12-18 02:08

    i also used the same stackOverflow answer, and get the same problem.so:

    i've added this code

    this.setZOrderOnTop(true);
    SurfaceHolder h = this.getHolder();
    h.setFormat(PixelFormat.TRANSPARENT);
    

    to my surfaceChanged method, instead of the activity (or a service at my case), and got it trasparent, but the Log complains on abandoned frames :(

    0 讨论(0)
  • 2020-12-18 02:23

    You don't actually have to place the SurfaceView on your UI at all. We were running into the same issue and made a dummy SurfaceView. Here's our code:

    SurfaceView dummy = new SurfaceView(c);
    try {
        mCamera.setPreviewDisplay(dummy.getHolder());
    } catch (IOException e) {
    
    }
    mCamera.setPreviewCallback(this);
    mCamera.startPreview();
    
    0 讨论(0)
提交回复
热议问题