在Android模拟器中使用相机
我希望使用网络摄像头在 Android 模拟器中模拟摄像头。基本上我只需要在模拟器中用相机拍照(不需要实时预览,即如果它使它变得更容易)
我按照教程here 这是我能找到的唯一一个接近我的要求的
但是该教程中使用的许多库(如 android.hardware.CameraDevice)在当前的 sdk 中不可用并被新的库取代(如 android.hardware.camera)。
任何有关如何在当前 sdk(2.1 或 2.2)中执行此操作的帮助将不胜感激。
I wish to simulate camera in the android emulator using the webcam. Basically I need to only take photos with the camera in the emulator (live preview is not needed i.e if it makes it any easier)
I followed the tutorial here which is the only one I could find that was close to my requirements
But many of the libraries used in that tutorial(like android.hardware.CameraDevice) are not available in present sdk and are replaced by new libraries(like android.hardware.camera).
Any help on how to do this in the present sdk(2.1 or 2.2) would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在 AVD 高级设置中,您应该能够将前置摄像头和后置摄像头设置为
Webcam()
或Emulated
。In your AVD advanced settings, you should be able to set front and back cameras to
Webcam()
orEmulated
.更新:ICS模拟器支持摄像头。
Update: ICS emulator supports camera.
一些详细说明,希望澄清已经说过的内容:
如上所述,当前 SDK 中本地支持网络摄像头,但仅在最近的 Android 版本(4.0 及更高版本)上
自动检测网络摄像头,其中展示。在 4.0.3 中,摄像头默认为前置摄像头,因此很多应用程序(特别是 2.3 之前的应用程序,只能获取默认摄像头,即后置摄像头)仍然会向您显示旧的复选框 - 带有- 移动方块代替。
我认为以下帖子中提供了更多信息: Android Eclipse 模拟器上的相机:
或者至少,这是我能找到的最多信息——除了 SDK 工具发行说明中简短、无信息的陈述。
Some elaboration, in the hope of clarifying what has already been said:
As stated above, Webcams are supported natively in the current SDK, but only on recent android versions (4.0 and higher)
Webcam detection is automatic where present. In 4.0.3, the camera defaults to the front-facing camera so a lot of applications (especially pre-2.3 applications, which can only fetch the default camera, i.e. the back-facing one) will still show you the old checkerbox-with-moving-square stand-in instead.
I think some more info is available in the following post: Camera on Android Eclipse emulator:
Or at least, that's the most information I've been able to find--aside from the brief, uninformative statements in the release notes for the SDK tools.
如果您使用命令行工具或只想直接编辑
config.ini
文件,您可以选择:选项 1:使用命令行选项
如果您如果想要使用实际摄像头而不是模拟摄像头,则该选项的值为
webcam${N}
。你怎么知道${N}
应该是什么?emulator -webcam-list
列出并描述了计算机上可用的摄像头。选项 2:编辑配置文件
使用上面学到的合法值,编辑文件
~/.android/avd/${MY_AVD}/config.ini
并添加一行(我将使用 < code>virtualscene 作为我选择的值):If you're working with command-line tools or just want to edit your
config.ini
file directly, you have options:Option 1: use command-line options
If you want to use your actual camera instead of a mock, the option's value will be
webcam${N}
. How do you know what${N}
should be?emulator -webcam-list
lists and describes the cameras available on your computer.Option 2: edit the config file
Using the legal values we learnt above, edit the file
~/.android/avd/${MY_AVD}/config.ini
and add a line (I'll usevirtualscene
as my value of choice):更新@param 的答案。
ICS模拟器支持相机。
我发现简单的Android照片捕捉,支持android模拟器中的网络摄像头。
Update of @param's answer.
ICS emulator supports camera.
I found Simple Android Photo Capture, which supports webcam in android emulator.
以防万一您只需要显示图片以响应相机请求,可以使用 image-to -相机。
只需下载、构建、安装、将您选择的图像复制到设备上,您就可以通过应用程序选择它,这是内置相机的替代方案。
Just in case you just need to show a picture in response to a camera request, there is image-to-camera.
Just download, build, install, copy an image of your choice to the device, and you can select it via the app, which is an alternative to the built-in camera.
看起来不像,但 Android 将网络摄像头识别为设备。每次我运行模拟器时,我的网络摄像头的活动灯都会亮起。
Does not seem like it, but android recognises a webcam as a device. Every time I run the emulator my webcam's active light comes on.
有 Tom Gibara 教程的更新版本。您可以将网络摄像头广播器更改为使用 JMyron 而不是旧的 JMF。
新的模拟器(sdk r15)管理网络摄像头;但集成网络摄像头有一些问题(至少我的^^)
There is an updated version of Tom Gibara's tutorial. You can change the Webcam Broadcaster to work with JMyron instead of the old JMF.
The new emulator (sdk r15) manage webcams ; but it has some problems with integrated webcams (at least with mine's ^^)
最新的camera2 api可以在启用了相机支持的模拟器上正常工作。
使用较新 API 的示例:
https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/AutoFitTextureView.java
The newest camera2 apis work fine w/ an emulator that has camera support enabled.
Example for using the newer API:
https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/AutoFitTextureView.java