Java Call Camera screenshot

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.