【发布时间】:2020-08-30 10:24:34
【问题描述】:
我创建了一个前台服务,目的是从 camera2 预览中获取帧,而不向用户显示布局。当我在布局中创建一个 Textureview 并使用它时,一切正常,我可以通过调用 TextureView 的 getBitmap(int width, int height) 来获取帧。我已经保存了框架,我知道它工作正常。这是我的代码:
textureView = mainActivity.findViewById(R.id.texture_view);
surfaceTexture = textureView.getSurfaceTexture();
surface = new Surface(surfaceTexture);
但我需要我的代码在没有布局的情况下工作。我以编程方式创建了一个 TextureView,但是当我运行它并保存帧时,它们是空白的。这是我运行的代码,使其无需布局即可工作:
textureView = new TextureView(context);
textureView.setSurfaceTexture(new SurfaceTexture(100));
surfaceTexture = textureView.getSurfaceTexture();
surface = new Surface(surfaceTexture);
仅供参考,我在工作线程上运行我的代码。我也尝试过使用这些对象的侦听器,但没有运气。谁能指出我正确的方向吗?
【问题讨论】:
标签: android android-camera2 surface textureview