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 ();
}