![](/img/trans.png)
[英]Getting android camera2 preview frames without lagging the screen preview
[英]How to get camera2 preview frames programmatically(without layout) in Android?
我创建了一个前台服务,目的是从 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);
仅供参考,我在工作线程上运行我的代码。 我也试过使用这些对象的监听器,但没有成功。 谁能指出我正确的方向?
我不认为你可以避免使用表面。 但也许你可以通过布局高度和宽度 0dp 动态膨胀它来逃避。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.