同时运行 2 个 Camera 实例

发布于 2024-10-10 12:04:03 字数 144 浏览 0 评论 0原文

我想知道在 android 中是否可以有 2 个相机预览实例。我的意思是同时运行相机的 2 个实例。如果是,如何解决这个问题,是否需要在不同的线程上实现一个实例?我以前没有使用过相机 API,所以如果我能了解这个问题,我将不胜感激,这样我就不会在这上面浪费时间了。 谢谢。

I was wondering whether it is possible to have 2 instances of the camera preview in android. What I mean is running 2 instances of the camera at the same time. If it is, how would one go about this, will there be need to implement an instance on a different thread? I have not used the camera API before, so I would appreciate it if I can have a heads up on the issue, so I don't waste time on it.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹沉浮 2024-10-17 12:04:03

不可能有两个与相机的开放连接 - 您必须锁定相机才能获得预览,并且只能锁定一次。事实上,如果您锁定了相机,并且您的应用程序在解锁之前崩溃了,那么没有人可以使用相机!

请参阅 http://developer.android.com/reference /android/hardware/Camera.html#open%28int%29

当你
使用相机完成,否则
将保持锁定状态并且不可用
到其他应用程序。

...

运行时异常:如果连接到
相机服务失败(例如,如果
相机已被其他人使用
过程)。

也就是说,您当然可以注册预览回调并从单个相机实例获取预览数据以在多个视图中使用。但请注意预览回调提供的原始 byte[] 数据的 YUV 格式的问题: 在 Android 中从视频图像获取帧(请注意,预览数据是来自相机驱动程序的原始数据,并且可能因设备而异)

It is not possible to have two open connections to the camera - you have to lock the camera in order to get a preview and it can only be locked once. Indeed, if you have the camera locked, and your app crashes before you've unlocked it, then nobody can use the camera!

See 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).

That said, you can certainly register a preview callback and take the preview data from your single camera instance to use in multiple views. But be aware of the issues with the YUV format of the raw byte[] data provided by the preview callback: Getting frames from Video Image in Android (note that the preview data is raw from the camera driver and may vary from device to device)

煮茶煮酒煮时光 2024-10-17 12:04:03

忽略这个重要的“为什么”问题,最好的选择是创建一个与相机交互的服务,然后从那里开始。

Ignoring the big Why question, your best bet would be to make a service that interacts with the camera, and go from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文