简体   繁体   English

如何同时使用前置和后置摄像头?

[英]How to use front and back camera at the same time?

I want to use both front and back cameras at the same time.我想同时使用前置和后置摄像头。 I have used two surface views.我使用了两个表面视图。 I have tried to implement the code in following answer.我试图在以下答案中实现代码。

https://stackoverflow.com/a/24238301/6874315 https://stackoverflow.com/a/24238301/6874315

The problem is that the camera API is now deprecated and the code was too old.问题是相机 API 现在已弃用,代码太旧。 I tried using the Camera 2 API in the same way but the camera instance won't open and i get a blank white screen.我尝试以相同的方式使用相机 2 API,但相机实例无法打开,并且出现空白屏幕。 I get the following two errors:我收到以下两个错误:

Camera 0 not available.相机 0 不可用。 java.lang:RuntimeException: Fail to connect to camera service java.lang:RuntimeException: 无法连接到相机服务

Camera 1 not available.相机 1 不可用。 java.lang:RuntimeException: Fail to connect to camera service java.lang:RuntimeException: 无法连接到相机服务

What i wanna do is capture picture from front and back camera simultaneously on a button click.我想做的是通过单击按钮同时从前后摄像头捕获图片。 But i'm not able to open both front and back cameras at the same time.但我无法同时打开前后摄像头。 Is there anything that I do to use both cameras at same time?我有什么办法可以同时使用两个相机吗?

Take a look at these answers:看看这些答案:

https://stackoverflow.com/a/30444841/11338123 https://stackoverflow.com/a/30444841/11338123

https://stackoverflow.com/a/52075569/11338123 https://stackoverflow.com/a/52075569/11338123

I think it is possible in some devices and it is impossible in others我认为这在某些设备中是可能的,而在其他设备中是不可能的

I don't sure that it is possible to use both cameras simultaneously.我不确定是否可以同时使用两个相机。 But, you could switching between two cameras like in this sample for short time interval.但是,您可以在此示例中的两个摄像机之间切换很短的时间间隔。

Also you can modify you program to process camera images in the background thread in such way to avoid GUI freezing.您还可以修改程序以在后台线程中处理相机图像以避免 GUI 冻结。

So, you may try to make a little changes in the sample to get front and back camera instances for testing your idea.因此,您可以尝试对示例进行一些更改,以获得前后摄像头实例来测试您的想法。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM