problem in capturing webcam image
To capture image directly, I'm using the following code:
import java.io.*;
import java.awt.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import javax.media.util.*;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;
import javax.media.*;
import javax.media.control.*;
import javax.media.util.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import javax.media.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.util.*;
import javax.media.control.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
import java.io.IOException;
import java.util.Locale;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import com.sun.media.protocol.vfw.VFWCapture; // JMF 2.1.1e version
// set up player
JPanel videoPanel = new JPanel();
// note I just set the media locator directly
MediaLocator ml = new MediaLocator("vfw://0");
try {
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if ((comp = player.getVisualComponent()) != null) {
videoPanel.add(comp, BorderLayout.CENTER);
videoPanel.setSize(new Dimension(320, 240));
videoPanel.setMinimumSize(new Dimension(320, 240));
videoPanel.setMaximumSize(new Dimension(320, 240));
}
playerUp=true;
}
catch (Exception e) {
// process error
}
// action code on capture button
public void actionPerformed(ActionEvent e) {
JComponent c = (JComponent) e.getSource();
if (c == capture) {
// Grab the frame
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbi ngControl");
Buffer buf = fgc.grabFrame();
// Convert to image
BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
Image img = btoi.createImage(buf);
// now go and display the captured image
...
}
}
But it gives the error package javax.media does not exist. I'm using jdk 1.4. Classpath is set becoz it doesn't give error for javax.swing, which I'm using in my code. What could be the problem?
|