我想知道是否有可能在 android 中有 2 个相机预览实例。我的意思是同时运行 2 个相机实例。如果是这样,人们将如何处理这个问题,是否需要在不同的线程上实现一个实例?我以前没有使用过相机 API,所以如果我能提前了解这个问题,我将不胜感激,所以我不会在这上面浪费时间。 谢谢。
最佳答案
不可能有两个打开的相机连接 - 您必须锁定相机才能获得预览,并且只能锁定一次。事实上,如果您锁定了相机,并且您的应用程序在您解锁之前崩溃了,那么就没有人可以使用相机了!
参见 http://developer.android.com/reference/android/hardware/Camera.html#open%28int%29
You must call release() when you are done using the camera, otherwise it will remain locked and be unavailable to other applications.
...
RuntimeException: if connection to the camera service fails (for example, if the camera is in use by another process).
也就是说,您当然可以注册一个预览回调并从您的单个相机实例中获取预览数据以用于多个 View 。但请注意预览回调提供的原始 byte[] 数据的 YUV 格式问题:Getting frames from Video Image in Android (请注意,预览数据是来自相机驱动程序的原始数据,可能因设备而异)
关于android - 同时运行 Camera 的 2 个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4588869/