Java uses JMF to realize camera function

Source: Internet
Author: User

I split the program into two, interesting and uninteresting, and recently made a couple of interesting projects, one of which should be even a camera-taking program. Used for scene photography, photo generation, and primarily for the Java Media Framework (JMF).

First go to Sun to download the latest JMF, and then install. http://java.sun.com/products/java-media/jmf/index.jsp

Then, say the need

1. Take a picture with a camera

2. Enter a file name in the text box

3. Press the photo button to get the image inside the camera

4. There is a red box on the photo that captures the fixed size of the picture.

5. Save as a local image in JPG format, no compression

The key to the technology, I believe the most interesting part is how to get a camera to work, and take a picture.

With JMF, the code is simple:

Using these three classes to get the camera driver, and to obtain the image stream inside the camera, the image stream is captured by a swing component component class

public static Player player = null;
private CaptureDeviceInfo  di = null;
private MediaLocator ml = null;
String str1 = "vfw:Logitech USB  Video Camera:0";
String str2 =  "vfw:Microsoft WDM Image Capture (Win32):0";
di =  CaptureDeviceManager.getDevice(str2);
ml = di.getLocator();
try
{
player =  Manager.createRealizedPlayer (ml);
player.start();
Component comp;
if ((comp = player.getVisualComponent())  != null)
{
add(comp, BorderLayout.NORTH);
}
}
catch (Exception e)
{
e.printStackTrace ();
}

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.