【问题标题】:How to get camera2 preview frames programmatically(without layout) in Android?如何在 Android 中以编程方式(无布局)获取 camera2 预览帧?
【发布时间】: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


    【解决方案1】:

    我认为您无法避免使用表面。 但也许你可以用布局高度和宽度 0dp 动态膨胀它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-31
      • 2015-06-07
      • 2017-01-19
      • 2022-01-14
      • 2013-09-30
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多