Taking picture from non-activity

前端 未结 3 841
时光取名叫无心
时光取名叫无心 2021-01-02 22:23

I am using dummy surface in my code.It\'s working fine in Canvas HD running 4.2.1 but when the same app is deployed on my nexus 5/S 3 it gives RunTimeException on camera.tak

3条回答
  •  走了就别回头了
    2021-01-02 23:28

    You can use a dummy SurfaceTexture instead of a SurfaceView. This is reliable and works fine on the old camera API:

    mDummyTexture = new SurfaceTexture(1); // pick a random argument for texture id
    mCamera.setPreviewTexture(mDummyTexture);
    mCamera.startPreview();
    mCamera.takePicture(...);
    

    Just make sure to keep mDummyTexture as a member of your class, or you may get abandoned surface errors.

    As long as you don't call SurfaceTexture#updateTexImage(), you do not need an OpenGL context.

提交回复
热议问题