android - 同时运行 Camera 的 2 个实例

标签 android android-camera

我想知道是否有可能在 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/

相关文章:

Android相机 - 设置焦点区域导致运行时异常

android - 自定义照片文件夹显示在图库中

Android 服务无法启动 Intent 和 NullPointerException

android - 方向改变时相机出现问题

android - 在Android Studio中构建项目时,Gradle提供NullPointerException

android - 无法在 gradle 3.0.0 beta2 中配置 Realm 生成器

android - 拍照而不将图片保存到图库?

android - 相机屏幕方向问题三星盖乐世 S3

java - 设置值后 SharedPreferences 返回默认值

android - 减少 Google Play 商店上的应用更新大小