How to mock a picture in Android Emulator Camera?

China☆狼群 提交于 2020-12-27 07:59:26

问题


Is there a way to set a static picture as the photo been taken by the emulator camera? I would like to test ir with zxing barcode reader on emulator.


回答1:


This can be solved by adding a classic abstraction layer such as this gentleman has done in this sample source code:
http://www.tomgibara.com/android/camera-source

Specifically, sounds like you may want to have some test pictures and use the BitmapCamera




回答2:


If you are running the emulator on linux you can create a mock webcam showing an image (e.g. QRcode) with v4l2loopback and gstreamer.

Install v4l2loopback:

$ wget https://github.com/umlaeute/v4l2loopback/archive/master.zip
$ unzip master.zip
$ cd v4l2loopback
$ make
$ sudo make install

Check how many cameras you already have (I only had /dev/video0) and init the next one:

$ sudo modprobe v4l2loopback video_nr=1 card_label="mockCam"

Stream an image (for example a QR from googlecharts) to the mockCam. This requres :

$ wget "https://chart.googleapis.com/chart?chs=600x340&cht=qr&chl=testing" -O qr.png
$ gst-launch-0.10 filesrc location=qr.png ! pngdec ! freeze ! v4l2sink device=/dev/video1

You can check if your mock camera is picked up by the emulator:

$ ./emulator -avd yourAVD -webcam-list

If so, you can start the emulator with the mock webcam:

$ ./emulator -avd yourAVD -camera-back webcam1

You can also change the AVD setting to webcam1. Hope this helps.




回答3:


You can also use MockCamera for Android. See the detailed reference to answer. https://stackoverflow.com/a/38456086/1053097



来源:https://stackoverflow.com/questions/6165618/how-to-mock-a-picture-in-android-emulator-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!