Java Call camera
Recently, there is a need to call the camera through Java, and the need to find the information on the Internet, mostly with a library called JMF, but JMF has not been updated for hundreds of years, the use of various problems. Later found a library called FMJ, said is the replacement of JMF, but the information is too little, do not know how to start.
And found a search on the Internet to find an open source project Webcam-capture, really good. Basic examples are complete and quick to get started.
Webcam-capture Project Address: https://github.com/sarxos/webcam-capture
Using Webcam-capture to write a small demo, the code is as follows:
Public classcapturedemo{Private Static intnum = 0; Public Static voidMain (string[] args)throwsIOException {FinalWebcam Webcam =Webcam.getdefault (); Webcam.setviewsize (WebcamResolution.VGA.getSize ()); Webcampanel Panel=Newwebcampanel (webcam); Panel.setfpsdisplayed (true); Panel.setdisplaydebuginfo (true); Panel.setimagesizedisplayed (true); Panel.setmirrored (true); FinalJFrame window =NewJFrame ("Webcam"); Window.addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosed (windowevent e) {webcam.close (); Window.dispose (); } }); //window.setdefaultcloseoperation (jframe.exit_on_close); FinalJButton button =NewJButton (""); Window.add (panel, borderlayout.center); Window.add (button, Borderlayout.south); Window.setresizable (true); Window.pack (); Window.setvisible (true); Button.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent e) {button.setenabled (false); String FileName= "d://" +num; Webcamutils.capture (Webcam, fileName, imageutils.format_png); Swingutilities.invokelater (NewRunnable () {@Override Public voidrun () {Joptionpane.showmessagedialog (NULL, "Success"); Button.setenabled (true); Num++; return; } }); } }); }}
Java Call camera