The question:
As far as i know, Android emulator doesn’t have a camera. To capture a live image we have to use the web camera. I have seen code in this web site to use the web camera in the android emulator to capture an image, but I don’t know how to use this code.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
- Download all the source files listed on the page: CameraSource, GenuineCamera, HttpCamera, SocketCamera, BitmapCamera, and WebcamBroadcaster.
- Create a package in your project called com.tomgibara.android.camera and place the first 4 source files inside.
- Download JMF from here and install it.
- Compile WebcamBroadcaster using the following command: “C:Program Files (x86)Javajdk1.6.0_15binjavac.exe” -classpath “C:Program Files (x86)JMF2.1.1elib” WebcamBroadcaster.java or what’s equivalent to it.
- Run it with the following command and keep it running: java “-Djava.library.path=C:Program Files (x86)JMF2.1.1dlib” WebcamBroadcaster
- Use the following code in your program:
CameraSource cs = new SocketCamera("192.168.0.100", 9889, 320, 240, true); if (!cs.open()) { /* deal with failure to obtain camera */ } while(/*some condition*/) { cs.capture(canvas) //capture the frame onto the canvas } cs.close();
PS: I haven’t been able to test this because I’m getting an error when I run WebcamBroadcaster
.
PPS: I just started experimenting with Android today so all this could be wrong.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0