4

在测试 Android Camera2 API 的性能时,我注意到与ImageReader.

当应用程序启动时,onImageAvailable()函数被正确调用,但在锁定和解锁屏幕后,它根本没有被调用。我的应用程序中处理相机的部分基于 Camera2Basic Google 教程。

更重要的是,我已经安装了提供 Camera2 API 的Camera2Basic Android 演示应用程序,我发现即使是谷歌制作的这个应用程序也有同样的问题。

这个问题有什么解决办法吗?

在 Android Studio 中使用 Debug 工具一段时间后,我发现只有在用于预览的函数在函数中可用onImageAvailable()时才会出现调用函数 的问题。TextureViewonResume()

@Override
public void onResume() {
    super.onResume();
    startBackgroundThread();

    // When the screen is turned off and turned back on, the SurfaceTexture is already
    // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
    // a camera and start preview from here (otherwise, we wait until the surface is ready in
    // the SurfaceTextureListener).
    if (mTextureView.isAvailable()) {
        openCamera(mTextureView.getWidth(), mTextureView.getHeight());
    } else {
        mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
}

如果mTextureView.isAvailable()返回falseSurfaceTextureListener设置为 on,mTextureViewonImageAvailable()正确调用,但如果openCamera(mTextureView.getWidth(), mTextureView.getHeight())在问题中调用函数onResume()

4

0 回答 0